MCPcopy Create free account
hub / github.com/PRX/Infrastructure / handler

Function handler

ci/src/github-webhook-endpoint/index.mjs:33–72  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

31 * @throws GitHub webhook validation error
32 */
33export const handler = async (event) => {
34 const githubSignature = event.headers['x-hub-signature'].split('=')[1];
35
36 console.log(`Checking event signature: ${githubSignature}`);
37
38 const key = process.env.GITHUB_WEBHOOK_SECRET;
39 const data = event.body;
40 const check = createHmac('sha1', key).update(data).digest('hex');
41
42 if (githubSignature !== check) {
43 throw new Error('Invalid signature!');
44 }
45
46 console.log(`Handling event: ${event.headers['x-github-event']}`);
47 const body = event.isBase64Encoded
48 ? Buffer.from(event.body, 'base64').toString('utf-8')
49 : event.body;
50
51 console.log(body);
52
53 switch (event.headers['x-github-event']) {
54 case 'ping':
55 // Blackhole `ping` events
56 break;
57 default:
58 await eventbridge.send(
59 new PutEventsCommand({
60 Entries: [
61 {
62 Detail: body,
63 DetailType: event.headers['x-github-event'],
64 Source: 'org.prx.ci.github-webhook',
65 },
66 ],
67 }),
68 );
69 }
70
71 return OK_RESPONSE;
72};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected