From 0979fd7bef16b87f1a30af1fc75f5d947afaef2c Mon Sep 17 00:00:00 2001 From: whilefoo Date: Sun, 18 Feb 2024 13:44:51 +0100 Subject: [PATCH] feat: updated delegated compute inputs --- src/github/github-event-handler.ts | 1 - src/github/handlers/index.ts | 37 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/github/github-event-handler.ts b/src/github/github-event-handler.ts index 401cf81..36ffe88 100644 --- a/src/github/github-event-handler.ts +++ b/src/github/github-event-handler.ts @@ -41,7 +41,6 @@ export class GitHubEventHandler { } transformEvent(event: EmitterWebhookEvent) { - console.log(this); if ("installation" in event.payload && event.payload.installation?.id !== undefined) { const octokit = this.getAuthenticatedOctokit(event.payload.installation.id); return new GitHubContext(this, event, octokit); diff --git a/src/github/handlers/index.ts b/src/github/handlers/index.ts index be37360..d18bcbc 100644 --- a/src/github/handlers/index.ts +++ b/src/github/handlers/index.ts @@ -1,4 +1,4 @@ -import { EmitterWebhookEvent } from "@octokit/webhooks"; +import { EmitterWebhookEvent, EmitterWebhookEventName } from "@octokit/webhooks"; import { GitHubEventHandler } from "../github-event-handler"; import { getConfig } from "../utils/config"; import { issueCommentCreated } from "./issue-comment/created"; @@ -41,15 +41,42 @@ async function handleEvent(event: EmitterWebhookEvent, eventHandler: InstanceTyp for (const { workflow, settings } of handler) { console.log(`Calling handler for event ${event.name} and workflow ${workflow}`); + let installationId: string | undefined = undefined; + if ("installation" in event.payload && event.payload.installation?.id !== undefined) { + installationId = event.payload.installation.id.toString(); + } + + const inputs = new DelegatedComputeInputs(context.key, event, settings, installationId); + await dispatchWorkflow(context, { owner: workflow.owner, repository: workflow.repository, workflowId: workflow.workflowId, ref: workflow.branch, - inputs: { - event: JSON.stringify(event), - settings: JSON.stringify(settings), - }, + inputs: inputs.getInputs(), }); } } + +class DelegatedComputeInputs { + public eventName: T; + public event: EmitterWebhookEvent; + public settings: unknown; + public installationId?: string; + + constructor(eventName: T, event: EmitterWebhookEvent, settings: unknown, installationId?: string) { + this.eventName = eventName; + this.event = event; + this.settings = settings; + this.installationId = installationId; + } + + public getInputs() { + return { + eventName: this.eventName, + event: JSON.stringify(this.event), + settings: JSON.stringify(this.settings), + installationId: this.installationId ?? "", + }; + } +}