From d8ca2833e4042c0d62858543ac5b959125a90fbf Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 17 Jan 2025 13:58:42 +0900 Subject: [PATCH 1/2] fix: unified inputs for worker and action to generate the same payload and signature --- src/github/handlers/index.ts | 4 ++-- src/github/handlers/issue-comment-created.ts | 4 ++-- src/github/handlers/repository-dispatch.ts | 4 ++-- src/github/types/plugin.ts | 19 +------------------ tests/dispatch.test.ts | 2 +- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/github/handlers/index.ts b/src/github/handlers/index.ts index e7af706..2b29f82 100644 --- a/src/github/handlers/index.ts +++ b/src/github/handlers/index.ts @@ -104,14 +104,14 @@ async function handleEvent(event: EmitterWebhookEvent, eventHandler: InstanceTyp try { console.log(`Dispatching event for ${JSON.stringify(plugin)}`); if (!isGithubPluginObject) { - await dispatchWorker(plugin, await inputs.getWorkerInputs()); + await dispatchWorker(plugin, await inputs.getInputs()); } else { await dispatchWorkflow(context, { owner: plugin.owner, repository: plugin.repo, workflowId: plugin.workflowId, ref: plugin.ref, - inputs: await inputs.getWorkflowInputs(), + inputs: await inputs.getInputs(), }); } console.log(`Event dispatched for ${JSON.stringify(plugin)}`); diff --git a/src/github/handlers/issue-comment-created.ts b/src/github/handlers/issue-comment-created.ts index 60d08bf..73e905a 100644 --- a/src/github/handlers/issue-comment-created.ts +++ b/src/github/handlers/issue-comment-created.ts @@ -195,14 +195,14 @@ The input will include the following fields: try { if (!isGithubPluginObject) { - await dispatchWorker(plugin, await inputs.getWorkerInputs()); + await dispatchWorker(plugin, await inputs.getInputs()); } else { await dispatchWorkflow(context, { owner: plugin.owner, repository: plugin.repo, workflowId: plugin.workflowId, ref: ref, - inputs: await inputs.getWorkflowInputs(), + inputs: await inputs.getInputs(), }); } } catch (e) { diff --git a/src/github/handlers/repository-dispatch.ts b/src/github/handlers/repository-dispatch.ts index dd4b169..581f415 100644 --- a/src/github/handlers/repository-dispatch.ts +++ b/src/github/handlers/repository-dispatch.ts @@ -73,10 +73,10 @@ export async function repositoryDispatch(context: GitHubContext<"repository_disp repository: nextPlugin.plugin.repo, ref: nextPlugin.plugin.ref, workflowId: nextPlugin.plugin.workflowId, - inputs: await inputs.getWorkflowInputs(), + inputs: await inputs.getInputs(), }); } else { - await dispatchWorker(nextPlugin.plugin, await inputs.getWorkerInputs()); + await dispatchWorker(nextPlugin.plugin, await inputs.getInputs()); } } diff --git a/src/github/types/plugin.ts b/src/github/types/plugin.ts index ee00902..3ac7620 100644 --- a/src/github/types/plugin.ts +++ b/src/github/types/plugin.ts @@ -44,7 +44,7 @@ export class PluginInput = { diff --git a/tests/dispatch.test.ts b/tests/dispatch.test.ts index 365b51e..4337db6 100644 --- a/tests/dispatch.test.ts +++ b/tests/dispatch.test.ts @@ -29,7 +29,7 @@ jest.mock("../src/github/types/plugin", () => { return { ...originalModule, PluginInput: class extends originalModule.PluginInput { - async getWorkerInputs() { + async getInputs() { return { stateId: this.stateId, eventName: this.eventName, From 5e9adb29813c5deeb7f0102dabf91a1d844941f1 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 17 Jan 2025 15:19:13 +0900 Subject: [PATCH 2/2] test: fixed get inputs type to match changes --- tests/dispatch.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/dispatch.test.ts b/tests/dispatch.test.ts index 4337db6..49fb97a 100644 --- a/tests/dispatch.test.ts +++ b/tests/dispatch.test.ts @@ -33,12 +33,12 @@ jest.mock("../src/github/types/plugin", () => { return { stateId: this.stateId, eventName: this.eventName, - eventPayload: this.eventPayload, - settings: this.settings, + eventPayload: JSON.stringify(this.eventPayload), + settings: JSON.stringify(this.settings), authToken: this.authToken, ref: this.ref, signature: "", - command: this.command, + command: JSON.stringify(this.command), }; } },