Skip to content

Commit

Permalink
Merge pull request #233 from gentlementlegen/fix/payload-signature
Browse files Browse the repository at this point in the history
fix: unified inputs for worker and action to generate the same payload and signature
  • Loading branch information
gentlementlegen authored Jan 17, 2025
2 parents 32996e5 + 5e9adb2 commit bec803b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/github/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ async function handleEvent(event: EmitterWebhookEvent, eventHandler: InstanceTyp
try {
console.log(`Dispatching event for ${JSON.stringify(plugin)}`);
if (!isGithubPluginObject) {
await dispatchWorker(plugin, await inputs.getWorkerInputs());
await dispatchWorker(plugin, await inputs.getInputs());
} else {
await dispatchWorkflow(context, {
owner: plugin.owner,
repository: plugin.repo,
workflowId: plugin.workflowId,
ref: plugin.ref,
inputs: await inputs.getWorkflowInputs(),
inputs: await inputs.getInputs(),
});
}
console.log(`Event dispatched for ${JSON.stringify(plugin)}`);
Expand Down
4 changes: 2 additions & 2 deletions src/github/handlers/issue-comment-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ The input will include the following fields:

try {
if (!isGithubPluginObject) {
await dispatchWorker(plugin, await inputs.getWorkerInputs());
await dispatchWorker(plugin, await inputs.getInputs());
} else {
await dispatchWorkflow(context, {
owner: plugin.owner,
repository: plugin.repo,
workflowId: plugin.workflowId,
ref: ref,
inputs: await inputs.getWorkflowInputs(),
inputs: await inputs.getInputs(),
});
}
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/github/handlers/repository-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export async function repositoryDispatch(context: GitHubContext<"repository_disp
repository: nextPlugin.plugin.repo,
ref: nextPlugin.plugin.ref,
workflowId: nextPlugin.plugin.workflowId,
inputs: await inputs.getWorkflowInputs(),
inputs: await inputs.getInputs(),
});
} else {
await dispatchWorker(nextPlugin.plugin, await inputs.getWorkerInputs());
await dispatchWorker(nextPlugin.plugin, await inputs.getInputs());
}
}

Expand Down
19 changes: 1 addition & 18 deletions src/github/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEvent
this.command = command;
}

public async getWorkflowInputs() {
public async getInputs() {
const inputs = {
stateId: this.stateId,
eventName: this.eventName,
Expand All @@ -60,23 +60,6 @@ export class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEvent
signature,
};
}

public async getWorkerInputs() {
const inputs = {
stateId: this.stateId,
eventName: this.eventName,
eventPayload: this.eventPayload,
settings: this.settings,
authToken: this.authToken,
ref: this.ref,
command: this.command,
};
const signature = await this.eventHandler.signPayload(JSON.stringify(inputs));
return {
...inputs,
signature,
};
}
}

export type PluginChainState<T extends EmitterWebhookEventName = EmitterWebhookEventName> = {
Expand Down
8 changes: 4 additions & 4 deletions tests/dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ jest.mock("../src/github/types/plugin", () => {
return {
...originalModule,
PluginInput: class extends originalModule.PluginInput {
async getWorkerInputs() {
async getInputs() {
return {
stateId: this.stateId,
eventName: this.eventName,
eventPayload: this.eventPayload,
settings: this.settings,
eventPayload: JSON.stringify(this.eventPayload),
settings: JSON.stringify(this.settings),
authToken: this.authToken,
ref: this.ref,
signature: "",
command: this.command,
command: JSON.stringify(this.command),
};
}
},
Expand Down

0 comments on commit bec803b

Please sign in to comment.