diff --git a/packages/core/pipeline/src/access/api.ts b/packages/core/pipeline/src/access/api.ts index 72937697..a350e8ef 100644 --- a/packages/core/pipeline/src/access/api.ts +++ b/packages/core/pipeline/src/access/api.ts @@ -41,6 +41,10 @@ export type AccessContext = { export abstract class BaseAccess implements IAccess { ctx!: AccessContext; + setCtx(ctx: AccessContext) { + this.ctx = ctx; + } + async onRequest(req: AccessRequestHandleReq) { if (!req.action) { throw new Error("action is required"); diff --git a/packages/core/pipeline/src/access/decorator.ts b/packages/core/pipeline/src/access/decorator.ts index 2abcd904..a0c19eee 100644 --- a/packages/core/pipeline/src/access/decorator.ts +++ b/packages/core/pipeline/src/access/decorator.ts @@ -56,6 +56,6 @@ export function newAccess(type: string, input: any, ctx?: AccessContext) { utils, }; } - access.ctx = ctx; + access.setCtx(ctx); return access; } diff --git a/packages/core/pipeline/src/notification/api.ts b/packages/core/pipeline/src/notification/api.ts index 8488a690..338b8033 100644 --- a/packages/core/pipeline/src/notification/api.ts +++ b/packages/core/pipeline/src/notification/api.ts @@ -93,4 +93,19 @@ export abstract class BaseNotification implements INotification { } throw new Error(`action ${req.action} not found`); } + + async onTestRequest() { + await this.send({ + userId: 0, + title: "测试通知", + content: "测试通知", + pipeline: { + id: 1, + title: "测试流水线", + } as any, + pipelineId: 1, + historyId: 1, + url: "http://www.baidu.com", + }); + } } diff --git a/packages/core/pipeline/src/notification/decorator.ts b/packages/core/pipeline/src/notification/decorator.ts index ac80b14c..66b17b4d 100644 --- a/packages/core/pipeline/src/notification/decorator.ts +++ b/packages/core/pipeline/src/notification/decorator.ts @@ -44,13 +44,13 @@ export function newNotification(type: string, input: any, ctx: NotificationConte throw new Error(`notification ${type} not found`); } // @ts-ignore - const access = new register.target(); + const plugin = new register.target(); for (const key in input) { - access[key] = input[key]; + plugin[key] = input[key]; } if (!ctx) { throw new Error("ctx is required"); } - access.ctx = ctx; - return access; + plugin.setCtx(ctx); + return plugin; } diff --git a/packages/ui/certd-client/src/components/plugins/common/api-test.vue b/packages/ui/certd-client/src/components/plugins/common/api-test.vue index 7749e49f..23e3f60e 100644 --- a/packages/ui/certd-client/src/components/plugins/common/api-test.vue +++ b/packages/ui/certd-client/src/components/plugins/common/api-test.vue @@ -11,12 +11,15 @@