Skip to content

Commit a72b737

Browse files
fix(webhook): Fix publish events to EventBridge (#5143)
## Description Rollback changes introduced on #5030. The webhook lambda in the EventBridge mode is not supporting other events beside `workflow_job`. ## Related Issues This PR fixes #5142. --------- Co-authored-by: Brend Smits <brend.smits@philips.com>
1 parent 5a3746d commit a72b737

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • lambdas/functions/webhook/src/webhook

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

Lines changed: 13 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,16 @@ 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+
// If workflow_job event, read the event and log relevant information for monitoring and debugging purposes.
47+
if (eventType === 'workflow_job') {
48+
readWorkflowJobEvent(headers, body);
49+
}
50+
51+
const checkBodySizeResult = checkBodySize(body, headers);
4552

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

129-
function readEvent(
136+
// Reads the workflow_job event from the request body and headers, and logs relevant information for monitoring and debugging purposes.
137+
function readWorkflowJobEvent(
130138
headers: IncomingHttpHeaders,
131139
body: string,
132-
allowedEvents: string[],
133140
): { event: WorkflowJobEvent; eventType: string } {
134141
const eventType = headers['x-github-event'] as string;
135-
checkEventIsSupported(eventType, allowedEvents);
142+
checkEventIsSupported(eventType, ['workflow_job']);
136143

137144
const event = JSON.parse(body) as WorkflowJobEvent;
138145
logger.appendPersistentKeys({

0 commit comments

Comments
 (0)