Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ export type EmitterEvent = EmitterEventMap[EmitterEventName];

export type EmitterAnyEvent = EmitterWebhookEventMap["*"];

export type ToWebhookEvent<
TEmitterEvent extends string
> = TEmitterEvent extends `${infer TWebhookEvent}.${string}`
? TWebhookEvent
: TEmitterEvent;

interface BaseWebhookEvent<
TName extends keyof EmitterEventPayloadMap = keyof EmitterEventPayloadMap
> {
id: string;
name: TName;
name: ToWebhookEvent<TName>;
payload: EmitterEventPayloadMap[TName];
}

Expand Down
26 changes: 25 additions & 1 deletion test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ const fn = (webhookEvent: EmitterWebhookEvent) => {
console.log(webhookEvent.payload.sender);
}
}
// @ts-expect-error TS2367:
// This condition will always return 'false' since the types '"*" | "check_run" | ... many more ... | "workflow_run"' and '"check_run.completed"' have no overlap.
if (webhookEvent.name === "check_run.completed") {
console.log(webhookEvent.payload.action);
//
}

if (webhookEvent.name === "*") {
Expand Down Expand Up @@ -170,6 +172,28 @@ export default async function () {
}
});

webhooks.on(["check_run.completed", "code_scanning_alert.fixed"], (event) => {
if (event.name === "check_run") {
console.log(`a run was ${event.payload.action}!`);

if (event.payload.action === "completed") {
console.log("it was the completed action, obviously!");
}

// @ts-expect-error TS2367:
// This condition will always return 'false' since the types '"completed"' and '"created"' have no overlap.
if (event.payload.action === "created") {
//
}
}

// @ts-expect-error TS2367:
// This condition will always return 'false' since the types '"check_run" | "code_scanning_alert"' and '"repository"' have no overlap.
if (event.name === "repository") {
//
}
});

webhooks.on("issues", (event) => {
console.log(event.payload.issue);
});
Expand Down