Skip to content

Commit 1f9805d

Browse files
refactor(webhook): add persistent keys in logs (#5030)
## Summary Update `publishOnEventBridge` to use the existing `readEvent` helper instead of directly reading the `x-github-event` header and calling `checkEventIsSupported`. Only `eventType` is destructured from `readEvent`, since the parsed event object isn’t needed. ## Why This makes the EventBridge path consistent with `publishForRunners`, ensuring persistent logging fields (repository, action, workflow job name, status, etc.) are added to the logger in both code paths. ## Impact * No functional changes * Consistent logging behavior * Removes duplicate event parsing logic
1 parent d5efde5 commit 1f9805d

File tree

1 file changed

+9
-6
lines changed
  • lambdas/functions/webhook/src/webhook

1 file changed

+9
-6
lines changed

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

Lines changed: 9 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);
24+
const { event, eventType } = readEvent(headers, body, ['workflow_job']);
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,11 +39,10 @@ export async function publishOnEventBridge(
3939

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

42-
const eventType = headers['x-github-event'] as string;
43-
checkEventIsSupported(eventType, config.allowedEvents);
44-
4542
const checkBodySizeResult = checkBodySize(body, headers);
4643

44+
const { eventType } = readEvent(headers, body, config.allowedEvents);
45+
4746
logger.info(
4847
`Github event ${headers['x-github-event'] as string} accepted for ` +
4948
`${headers['x-github-hook-installation-target-id'] as string}`,
@@ -127,9 +126,13 @@ function checkEventIsSupported(eventType: string, allowedEvents: string[]): void
127126
}
128127
}
129128

130-
function readEvent(headers: IncomingHttpHeaders, body: string): { event: WorkflowJobEvent; eventType: string } {
129+
function readEvent(
130+
headers: IncomingHttpHeaders,
131+
body: string,
132+
allowedEvents: string[],
133+
): { event: WorkflowJobEvent; eventType: string } {
131134
const eventType = headers['x-github-event'] as string;
132-
checkEventIsSupported(eventType, ['workflow_job']);
135+
checkEventIsSupported(eventType, allowedEvents);
133136

134137
const event = JSON.parse(body) as WorkflowJobEvent;
135138
logger.appendPersistentKeys({

0 commit comments

Comments
 (0)