diff --git a/README.md b/README.md index 4dcb9f1..a010c0d 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 0000000..c128a96 --- /dev/null +++ b/manifest.json @@ -0,0 +1,11 @@ +{ + "name": "ts-template", + "description": "ts-template for Ubiquibot plugins.", + "ubiquity:listeners": [ "issue_comment.created" ], + "commands": { + "command1": { + "ubiquity:example": "/command1 argument", + "description": "Command 1 with an argument." + } + } +} diff --git a/src/worker.ts b/src/worker.ts index 3048b5d..40df400 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 7967004..8ca2780 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,7 +1,9 @@ +import { drop } from "@mswjs/data"; 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()); @@ -9,6 +11,7 @@ afterAll(() => server.close()); describe("User tests", () => { beforeEach(() => { + drop(db); for (const item of usersGet) { db.users.create(item); } @@ -19,4 +22,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); + }); });