Skip to content

Commit

Permalink
feat: updated delegated compute inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Feb 18, 2024
1 parent ea1b1d7 commit 0979fd7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/github/github-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 32 additions & 5 deletions src/github/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<T extends EmitterWebhookEventName = EmitterWebhookEventName> {
public eventName: T;
public event: EmitterWebhookEvent<T>;
public settings: unknown;
public installationId?: string;

constructor(eventName: T, event: EmitterWebhookEvent<T>, 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 ?? "",
};
}
}

0 comments on commit 0979fd7

Please sign in to comment.