From 9fed981deb143ef8157137b4c276c2604ad2a9c8 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 17 Jan 2025 13:58:42 +0900 Subject: [PATCH 01/14] 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 e30217bec0009c3bc57dbce099bd1f2abb76a490 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 17 Jan 2025 15:19:13 +0900 Subject: [PATCH 02/14] 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), }; } }, From 904aca791416528542b7b73c8fee5faa3f37d8c9 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 27 Dec 2024 15:58:53 +0900 Subject: [PATCH 03/14] chore: added req log --- src/kernel.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kernel.ts b/src/kernel.ts index cd1446d..92cb08a 100644 --- a/src/kernel.ts +++ b/src/kernel.ts @@ -37,6 +37,9 @@ app.post("/", async (ctx: Context) => { pluginChainState: new EmptyStore(), openAiClient, }); + eventHandler.onAny(() => { + console.log(`Received POST from ${ctx.req.url}`); + }); bindHandlers(eventHandler); // if running in Cloudflare Worker, handle the webhook in the background and return a response immediately From 127679faf1da17f7c548487697c08a694172e199 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Sat, 18 Jan 2025 12:16:41 +0900 Subject: [PATCH 04/14] fix: the default values for skipBotEvents and ubiquity:listeners is no longer overridden --- src/github/utils/config.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/github/utils/config.ts b/src/github/utils/config.ts index 0f9f42b..35063ef 100644 --- a/src/github/utils/config.ts +++ b/src/github/utils/config.ts @@ -92,9 +92,8 @@ export async function getConfig(context: GitHubContext): Promise Date: Sat, 18 Jan 2025 12:31:50 +0900 Subject: [PATCH 05/14] test: fixed tests to match skipBotEvents changes --- tests/configuration.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index 796dcf3..2d4b080 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -54,6 +54,7 @@ describe("Configuration tests", () => { plugins: - uses: - plugin: ubiquity/user-activity-watcher:compute.yml@fork/pull/1 + skipBotEvents: false with: settings1: 'enabled'`; } else { @@ -187,7 +188,6 @@ describe("Configuration tests", () => { "ubiquity:example": "/command" } }, - "skipBotEvents": false } `; } else if (args.path === CONFIG_FULL_PATH) { @@ -195,6 +195,7 @@ describe("Configuration tests", () => { plugins: - uses: - plugin: ubiquity/test-plugin + skipBotEvents: false with: settings1: 'enabled'`; } else { From 0921d5b2ee72954f7bb8cac787fbd0bde824a659 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 27 Dec 2024 15:58:53 +0900 Subject: [PATCH 06/14] chore: added req log --- src/kernel.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kernel.ts b/src/kernel.ts index cd1446d..92cb08a 100644 --- a/src/kernel.ts +++ b/src/kernel.ts @@ -37,6 +37,9 @@ app.post("/", async (ctx: Context) => { pluginChainState: new EmptyStore(), openAiClient, }); + eventHandler.onAny(() => { + console.log(`Received POST from ${ctx.req.url}`); + }); bindHandlers(eventHandler); // if running in Cloudflare Worker, handle the webhook in the background and return a response immediately From 144cc558c9d8328d893d094cf5ba05877f5d736a Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Sat, 18 Jan 2025 12:16:41 +0900 Subject: [PATCH 07/14] fix: the default values for skipBotEvents and ubiquity:listeners is no longer overridden --- src/github/utils/config.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/github/utils/config.ts b/src/github/utils/config.ts index ca77b58..5e03361 100644 --- a/src/github/utils/config.ts +++ b/src/github/utils/config.ts @@ -93,9 +93,8 @@ export async function getConfig(context: GitHubContext): Promise Date: Sat, 18 Jan 2025 12:31:50 +0900 Subject: [PATCH 08/14] test: fixed tests to match skipBotEvents changes --- tests/configuration.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index 796dcf3..2d4b080 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -54,6 +54,7 @@ describe("Configuration tests", () => { plugins: - uses: - plugin: ubiquity/user-activity-watcher:compute.yml@fork/pull/1 + skipBotEvents: false with: settings1: 'enabled'`; } else { @@ -187,7 +188,6 @@ describe("Configuration tests", () => { "ubiquity:example": "/command" } }, - "skipBotEvents": false } `; } else if (args.path === CONFIG_FULL_PATH) { @@ -195,6 +195,7 @@ describe("Configuration tests", () => { plugins: - uses: - plugin: ubiquity/test-plugin + skipBotEvents: false with: settings1: 'enabled'`; } else { From 20acfb536499c96d465e0b2bcd00adb8d30df901 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 27 Dec 2024 15:58:53 +0900 Subject: [PATCH 09/14] chore: added req log --- src/kernel.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kernel.ts b/src/kernel.ts index cd1446d..92cb08a 100644 --- a/src/kernel.ts +++ b/src/kernel.ts @@ -37,6 +37,9 @@ app.post("/", async (ctx: Context) => { pluginChainState: new EmptyStore(), openAiClient, }); + eventHandler.onAny(() => { + console.log(`Received POST from ${ctx.req.url}`); + }); bindHandlers(eventHandler); // if running in Cloudflare Worker, handle the webhook in the background and return a response immediately From 614ad9a4a6797059136528822d1c3f6e74d426a3 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 21 Jan 2025 08:44:59 +0900 Subject: [PATCH 10/14] chore: removed unused code --- src/kernel.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/kernel.ts b/src/kernel.ts index 92cb08a..cd1446d 100644 --- a/src/kernel.ts +++ b/src/kernel.ts @@ -37,9 +37,6 @@ app.post("/", async (ctx: Context) => { pluginChainState: new EmptyStore(), openAiClient, }); - eventHandler.onAny(() => { - console.log(`Received POST from ${ctx.req.url}`); - }); bindHandlers(eventHandler); // if running in Cloudflare Worker, handle the webhook in the background and return a response immediately From 9124733f7b0c6b221fccbe968497578a96d8118c Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 21 Jan 2025 08:49:36 +0900 Subject: [PATCH 11/14] chore: changed logic to default `skipBotEvents` setting --- src/github/utils/config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/github/utils/config.ts b/src/github/utils/config.ts index 5e03361..fc7de11 100644 --- a/src/github/utils/config.ts +++ b/src/github/utils/config.ts @@ -93,8 +93,9 @@ export async function getConfig(context: GitHubContext): Promise Date: Tue, 21 Jan 2025 09:23:02 +0900 Subject: [PATCH 12/14] chore: check for manifest values before override --- src/github/utils/config.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/github/utils/config.ts b/src/github/utils/config.ts index fc7de11..fb8e1aa 100644 --- a/src/github/utils/config.ts +++ b/src/github/utils/config.ts @@ -94,8 +94,12 @@ export async function getConfig(context: GitHubContext): Promise Date: Tue, 21 Jan 2025 09:50:13 +0900 Subject: [PATCH 13/14] chore: added undefined state to skipBotEvents --- src/github/types/plugin-configuration.ts | 2 +- src/github/utils/config.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/github/types/plugin-configuration.ts b/src/github/types/plugin-configuration.ts index 7627b6f..f2e49a4 100644 --- a/src/github/types/plugin-configuration.ts +++ b/src/github/types/plugin-configuration.ts @@ -60,7 +60,7 @@ const pluginChainSchema = T.Array( plugin: githubPluginType(), with: T.Record(T.String(), T.Unknown(), { default: {} }), runsOn: T.Array(emitterType, { default: [] }), - skipBotEvents: T.Boolean({ default: true }), + skipBotEvents: T.Optional(T.Boolean({ default: true })), }), { minItems: 1, default: [] } ); diff --git a/src/github/utils/config.ts b/src/github/utils/config.ts index fb8e1aa..5490404 100644 --- a/src/github/utils/config.ts +++ b/src/github/utils/config.ts @@ -97,8 +97,8 @@ export async function getConfig(context: GitHubContext): Promise Date: Tue, 21 Jan 2025 10:15:48 +0900 Subject: [PATCH 14/14] test: updated test for skipBotEvents --- tests/configuration.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index 2d4b080..12e4130 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -188,6 +188,7 @@ describe("Configuration tests", () => { "ubiquity:example": "/command" } }, + "skipBotEvents": true } `; } else if (args.path === CONFIG_FULL_PATH) {