diff --git a/src/actions.ts b/src/actions.ts index 3ffd894..48884d2 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -1,7 +1,6 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; import { EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; -import { Type as T } from "@sinclair/typebox"; import { Value } from "@sinclair/typebox/value"; import { LogReturn, Logs } from "@ubiquity-os/ubiquity-os-logger"; import { config } from "dotenv"; @@ -9,24 +8,12 @@ import { postComment } from "./comment"; import { Context } from "./context"; import { customOctokit } from "./octokit"; import { verifySignature } from "./signature"; -import { commandCallSchema } from "./types/command"; +import { inputSchema } from "./types/input-schema"; import { HandlerReturn } from "./types/sdk"; -import { jsonType } from "./types/util"; import { getPluginOptions, Options } from "./util"; config(); -const inputSchema = T.Object({ - stateId: T.String(), - eventName: T.String(), - eventPayload: jsonType(T.Record(T.String(), T.Any())), - command: jsonType(commandCallSchema), - authToken: T.String(), - settings: jsonType(T.Record(T.String(), T.Any())), - ref: T.String(), - signature: T.String(), -}); - export async function createActionsPlugin( handler: (context: Context) => HandlerReturn, options?: Options diff --git a/src/server.ts b/src/server.ts index 70cb42e..f53af4f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,4 @@ import { EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; -import { Type as T } from "@sinclair/typebox"; import { Value } from "@sinclair/typebox/value"; import { LogReturn, Logs } from "@ubiquity-os/ubiquity-os-logger"; import { Hono } from "hono"; @@ -10,21 +9,11 @@ import { Context } from "./context"; import { PluginRuntimeInfo } from "./helpers/runtime-info"; import { customOctokit } from "./octokit"; import { verifySignature } from "./signature"; +import { inputSchema } from "./types/input-schema"; import { Manifest } from "./types/manifest"; import { HandlerReturn } from "./types/sdk"; import { getPluginOptions, Options } from "./util"; -const inputSchema = T.Object({ - stateId: T.String(), - eventName: T.String(), - eventPayload: T.Record(T.String(), T.Any()), - command: T.Union([T.Null(), T.Object({ name: T.String(), parameters: T.Unknown() })]), - authToken: T.String(), - settings: T.Record(T.String(), T.Any()), - ref: T.String(), - signature: T.String(), -}); - export function createPlugin( handler: (context: Context) => HandlerReturn, manifest: Manifest, @@ -49,11 +38,11 @@ export function createPlugin { expect(res.status).toEqual(400); }); it("Should deny POST request with invalid signature", async () => { - const inputs = await getWorkerInputs( - "stateId", - issueCommentedEvent.eventName, - issueCommentedEvent.eventPayload, - { shouldFail: false }, - "test", - "main", - null - ); + const inputs = await getInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, { shouldFail: false }, "test", "main", null); const res = await app.request("/", { headers: { @@ -193,7 +159,7 @@ describe("SDK worker tests", () => { { kernelPublicKey: publicKey } ); - const inputs = await getWorkerInputs( + const inputs = await getInputs( "stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, @@ -228,7 +194,7 @@ describe("SDK worker tests", () => { }); }); it("Should accept correct request", async () => { - const inputs = await getWorkerInputs( + const inputs = await getInputs( "stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, @@ -265,7 +231,7 @@ describe("SDK actions tests", () => { }; it("Should accept correct request", async () => { - const githubInputs = await getWorkflowInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "main", { + const githubInputs = await getInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "main", { name: "test", parameters: { param1: "test" }, }); @@ -327,7 +293,7 @@ describe("SDK actions tests", () => { }); }); it("Should deny invalid signature", async () => { - const githubInputs = await getWorkflowInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "main", null); + const githubInputs = await getInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "main", null); jest.unstable_mockModule("@actions/github", () => ({ default: {}, @@ -364,7 +330,7 @@ describe("SDK actions tests", () => { expect(setOutput).not.toHaveBeenCalled(); }); it("Should accept inputs in different order", async () => { - const githubInputs = await getWorkflowInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "main", null); + const githubInputs = await getInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "main", null); jest.unstable_mockModule(githubActionImportPath, () => ({ default: {},