Skip to content
Open
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
19 changes: 13 additions & 6 deletions lambdas/functions/webhook/src/webhook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function publishForRunners(

const checkBodySizeResult = checkBodySize(body, headers);

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

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

const checkBodySizeResult = checkBodySize(body, headers);
// Check for supported event types allowed to send to event bridge
const eventType = headers['x-github-event'] as string;
checkEventIsSupported(eventType, config.allowedEvents);
Comment thread
andrecastro marked this conversation as resolved.

const { eventType } = readEvent(headers, body, config.allowedEvents);
// If workflow_job event, read the event and log relevant information for monitoring and debugging purposes.
if (eventType === 'workflow_job') {
readWorkflowJobEvent(headers, body);
}

const checkBodySizeResult = checkBodySize(body, headers);

logger.info(
`Github event ${headers['x-github-event'] as string} accepted for ` +
Expand Down Expand Up @@ -126,13 +133,13 @@ function checkEventIsSupported(eventType: string, allowedEvents: string[]): void
}
}

function readEvent(
// Reads the workflow_job event from the request body and headers, and logs relevant information for monitoring and debugging purposes.
function readWorkflowJobEvent(
headers: IncomingHttpHeaders,
body: string,
allowedEvents: string[],
): { event: WorkflowJobEvent; eventType: string } {
const eventType = headers['x-github-event'] as string;
checkEventIsSupported(eventType, allowedEvents);
checkEventIsSupported(eventType, ['workflow_job']);

const event = JSON.parse(body) as WorkflowJobEvent;
logger.appendPersistentKeys({
Expand Down