MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / webhookHandler

Function webhookHandler

integrations/github/src/sources.ts:224–296  ·  view source on GitHub ↗
(event: HandlerEvent<"HTTP">, logger: Logger)

Source from the content-addressed store, hash-verified

222}
223
224async function webhookHandler(event: HandlerEvent<"HTTP">, logger: Logger) {
225 logger.debug("[inside github integration] Handling github repo event");
226
227 const { rawEvent: request, source } = event;
228
229 if (!request.body) {
230 logger.debug("[inside github integration] No body found");
231
232 return;
233 }
234
235 const rawBody = await request.text();
236
237 const deliveryId = request.headers.get("x-github-delivery");
238 const hookId = request.headers.get("x-github-hook-id");
239 const signature = request.headers.get("x-hub-signature-256");
240
241 if (source.secret && signature) {
242 const githubWebhooks = new Webhooks({
243 secret: source.secret,
244 });
245
246 if (!githubWebhooks.verify(rawBody, signature)) {
247 logger.debug("[inside github integration] Unable to verify the signature of the rawBody", {
248 signature,
249 secret: source.secret,
250 });
251
252 return;
253 }
254 }
255
256 const name = request.headers.get("x-github-event") ?? "unknown";
257 const allHeaders = Object.fromEntries(request.headers.entries());
258
259 const context = omit(allHeaders, [
260 "x-github-event",
261 "x-github-delivery",
262 "x-hub-signature-256",
263 "x-hub-signature",
264 "content-type",
265 "content-length",
266 "accept",
267 "accept-encoding",
268 "x-forwarded-proto",
269 ]);
270
271 const payload = parseBody(rawBody);
272
273 if (!payload) {
274 logger.debug("[inside github integration] Unable to parse the rawBody");
275
276 return;
277 }
278
279 logger.debug("[inside github integration] Returning an event for the webhook!", {
280 name,
281 payload,

Callers

nothing calls this directly

Calls 6

omitFunction · 0.90
parseBodyFunction · 0.85
verifyMethod · 0.80
debugMethod · 0.65
textMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…