Skip to content

Commit

Permalink
Merge pull request actions#12 from gentlementlegen/main
Browse files Browse the repository at this point in the history
Manifest File
  • Loading branch information
gentlementlegen authored Jul 17, 2024
2 parents 67c9bcd + b95310d commit e72ed38
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
9 changes: 9 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
@@ -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<Response> {
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,
Expand Down
10 changes: 10 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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());
afterAll(() => server.close());

describe("User tests", () => {
beforeEach(() => {
drop(db);
for (const item of usersGet) {
db.users.create(item);
}
Expand All @@ -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);
});
});

0 comments on commit e72ed38

Please sign in to comment.