Skip to content

Commit a9ec51a

Browse files
committed
fix(webhook): Fix publish events to EventBridge
1 parent 1d57199 commit a9ec51a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • lambdas/functions/webhook/src/webhook

lambdas/functions/webhook/src/webhook/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function publishForRunners(
2121

2222
const checkBodySizeResult = checkBodySize(body, headers);
2323

24-
const { event, eventType } = readEvent(headers, body, ['workflow_job']);
24+
const { event, eventType } = readWorkflowJobEvent(headers, body);
2525
logger.info(`Github event ${event.action} accepted for ${event.repository.full_name}`);
2626
if (checkBodySizeResult.sizeExceeded) {
2727
// We only warn for large event, when moving the event bridge we can only can accept events up to 256KB
@@ -39,9 +39,11 @@ export async function publishOnEventBridge(
3939

4040
await verifySignature(headers, body, config.webhookSecret);
4141

42-
const checkBodySizeResult = checkBodySize(body, headers);
42+
// Check for supported event types allowed to send to event bridge
43+
const eventType = headers['x-github-event'] as string;
44+
checkEventIsSupported(eventType, config.allowedEvents);
4345

44-
const { eventType } = readEvent(headers, body, config.allowedEvents);
46+
const checkBodySizeResult = checkBodySize(body, headers);
4547

4648
logger.info(
4749
`Github event ${headers['x-github-event'] as string} accepted for ` +
@@ -126,13 +128,13 @@ function checkEventIsSupported(eventType: string, allowedEvents: string[]): void
126128
}
127129
}
128130

129-
function readEvent(
131+
// Reads the workflow_job event from the request body and headers, and logs relevant information for monitoring and debugging purposes.
132+
function readWorkflowJobEvent(
130133
headers: IncomingHttpHeaders,
131134
body: string,
132-
allowedEvents: string[],
133135
): { event: WorkflowJobEvent; eventType: string } {
134136
const eventType = headers['x-github-event'] as string;
135-
checkEventIsSupported(eventType, allowedEvents);
137+
checkEventIsSupported(eventType, ['workflow_job']);
136138

137139
const event = JSON.parse(body) as WorkflowJobEvent;
138140
logger.appendPersistentKeys({

0 commit comments

Comments
 (0)