From 4e9375123836592b2329388088c32974f7a0deae Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:15:54 +0900 Subject: [PATCH 1/4] chore: manifest.json --- README.md | 5 +++-- manifest.json | 10 ++++++++++ src/worker.ts | 9 +++++++++ tests/main.test.ts | 8 ++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 manifest.json diff --git a/README.md b/README.md index 4dcb9f150..a010c0d49 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ 1. Ensure you understand and have setup the [kernel](https://github.com/ubiquity/ubiquibot-kernel). 2. Update [compute.yml](./.github/workflows/compute.yml) with your plugin's name and update the `id`. 3. Update [context.ts](./src/types/context.ts) with the events that your plugin will fire on. -4. Update [plugin-inputs.ts](./src/types/plugin-inputs.ts) to match the `with:` settings in your org or repo level configuration. +4. Update [manifest.json](./manifest.json) with a proper description of your plugin. +5. Update [plugin-inputs.ts](./src/types/plugin-inputs.ts) to match the `with:` settings in your org or repo level configuration. - Your plugin config should look similar to this: @@ -43,7 +44,7 @@ ###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic. -5. Start building your plugin by adding your logic to the [plugin.ts](./src/plugin.ts) file. +6. Start building your plugin by adding your logic to the [plugin.ts](./src/plugin.ts) file. ## Testing a plugin diff --git a/manifest.json b/manifest.json new file mode 100644 index 000000000..8975439e7 --- /dev/null +++ b/manifest.json @@ -0,0 +1,10 @@ +{ + "name": "ts-template", + "description": "ts-template for Ubiquibot plugins.", + "commands": { + "command1": { + "example": "/command1 argument", + "description": "Command 1 with an argument." + } + } +} diff --git a/src/worker.ts b/src/worker.ts index 3048b5da9..40df4007c 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,10 +1,19 @@ import { Value } from "@sinclair/typebox/value"; import { plugin } from "./plugin"; import { Env, envValidator, pluginSettingsSchema, pluginSettingsValidator } from "./types"; +import manifest from "../manifest.json"; export default { async fetch(request: Request, env: Env): Promise { try { + if (request.method === "GET") { + const url = new URL(request.url); + if (url.pathname === "/manifest.json") { + return new Response(JSON.stringify(manifest), { + headers: { "content-type": "application/json" }, + }); + } + } if (request.method !== "POST") { return new Response(JSON.stringify({ error: `Only POST requests are supported.` }), { status: 405, diff --git a/tests/main.test.ts b/tests/main.test.ts index 79670049a..4f66d65c9 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -2,6 +2,7 @@ import { db } from "./__mocks__/db"; import { server } from "./__mocks__/node"; import usersGet from "./__mocks__/users-get.json"; import { expect, describe, beforeAll, beforeEach, afterAll, afterEach, it } from "@jest/globals"; +import manifest from "../manifest.json"; beforeAll(() => server.listen()); afterEach(() => server.resetHandlers()); @@ -19,4 +20,11 @@ describe("User tests", () => { const data = await res.json(); expect(data).toMatchObject(usersGet); }); + + it("Should serve the manifest file", async () => { + const worker = (await import("../src/worker")).default; + const response = await worker.fetch(new Request("http://localhost/manifest.json"), { SUPABASE_KEY: "", SUPABASE_URL: "" }); + const content = await response.json(); + expect(content).toEqual(manifest); + }); }); From fb0f9a822c9fc8367b930cfe50c10f1e89420c68 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:30:12 +0900 Subject: [PATCH 2/4] fix: drop db for each test to avoid duplicates --- tests/main.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/main.test.ts b/tests/main.test.ts index 4f66d65c9..8ca278080 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,3 +1,4 @@ +import { drop } from "@mswjs/data"; import { db } from "./__mocks__/db"; import { server } from "./__mocks__/node"; import usersGet from "./__mocks__/users-get.json"; @@ -10,6 +11,7 @@ afterAll(() => server.close()); describe("User tests", () => { beforeEach(() => { + drop(db); for (const item of usersGet) { db.users.create(item); } From 687b0fb8821bd1968650ecf3e62ed97b373284c8 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:10:02 +0900 Subject: [PATCH 3/4] chore: manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 8975439e7..d2cf6184e 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "description": "ts-template for Ubiquibot plugins.", "commands": { "command1": { - "example": "/command1 argument", + "ubiquity:example": "/command1 argument", "description": "Command 1 with an argument." } } From b95310d9993d2f9bd835241d006d26aa6734933a Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:56:54 +0900 Subject: [PATCH 4/4] chore: manifest.json --- manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.json b/manifest.json index d2cf6184e..c128a96cc 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,7 @@ { "name": "ts-template", "description": "ts-template for Ubiquibot plugins.", + "ubiquity:listeners": [ "issue_comment.created" ], "commands": { "command1": { "ubiquity:example": "/command1 argument",