(req, res)
| 38 | string, |
| 39 | string |
| 40 | > = async (req, res) => { |
| 41 | const secret = process.env.LINEAR_WEBHOOK_SECRET; |
| 42 | |
| 43 | if (!secret) { |
| 44 | throw new Error("LINEAR_WEBHOOK_SECRET is not set"); |
| 45 | } |
| 46 | |
| 47 | const expectedSignature = crypto |
| 48 | .createHmac("sha256", secret) |
| 49 | .update(req.body) |
| 50 | .digest("hex"); |
| 51 | |
| 52 | const linearSignature = req.headers["linear-signature"]; |
| 53 | if ( |
| 54 | typeof linearSignature !== "string" || |
| 55 | !timingSafeCompare(expectedSignature, linearSignature) |
| 56 | ) { |
| 57 | res.sendStatus(400); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const payload = JSON.parse(req.body) as LinearWebhookPayload; |
| 62 | |
| 63 | const temporalClient = await createTemporalClient(); |
| 64 | |
| 65 | const organizationId = payload.organizationId; |
| 66 | |
| 67 | if (!payload.data) { |
| 68 | res |
| 69 | .status(400) |
| 70 | .send( |
| 71 | `No data sent with ${payload.action} ${payload.type} webhook payload`, |
| 72 | ); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | const linearId = payload.data.id; |
| 77 | |
| 78 | if (!linearId) { |
| 79 | res |
| 80 | .status(400) |
| 81 | .send(`No ID found in ${payload.action} ${payload.type} webhook payload`); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | const { graphApi, vaultClient } = req.context; |
| 86 | |
| 87 | if (!vaultClient) { |
| 88 | logger.error("No vault client found in Linear webhook"); |
| 89 | res.sendStatus(500); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | const linearBotAccountId = await getMachineIdByIdentifier( |
| 94 | req.context, |
| 95 | { actorId: systemAccountId }, |
| 96 | { identifier: "linear" }, |
| 97 | ).then((maybeMachineId) => { |
nothing calls this directly
no test coverage detected