From 3abe1610bf7eebab06d787cfdfbfee1a4a282d18 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 7 Apr 2022 20:37:08 +0200 Subject: [PATCH] fix: Do not trigger >1 webhooks on GitLab --- src/lib/database/gitSources.ts | 1 - src/routes/webhooks/gitlab/events.ts | 19 +++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib/database/gitSources.ts b/src/lib/database/gitSources.ts index 7e4e90633..0ed6f29b1 100644 --- a/src/lib/database/gitSources.ts +++ b/src/lib/database/gitSources.ts @@ -26,7 +26,6 @@ export async function newSource({ name, teamId, type, htmlUrl, apiUrl, organizat }); } export async function removeSource({ id }) { - // TODO: Disconnect application with this sourceId! Maybe not needed? const source = await prisma.gitSource.delete({ where: { id }, include: { githubApp: true, gitlabApp: true } diff --git a/src/routes/webhooks/gitlab/events.ts b/src/routes/webhooks/gitlab/events.ts index 4a1eeafcc..f8bb54383 100644 --- a/src/routes/webhooks/gitlab/events.ts +++ b/src/routes/webhooks/gitlab/events.ts @@ -22,6 +22,15 @@ export const post: RequestHandler = async (event) => { const allowedActions = ['opened', 'reopen', 'close', 'open', 'update']; const body = await event.request.json(); const buildId = cuid(); + const webhookToken = event.request.headers.get('x-gitlab-token'); + if (!webhookToken) { + return { + status: 500, + body: { + message: 'Ooops, something is not okay, are you okay?' + } + }; + } try { const { object_kind: objectKind } = body; if (objectKind === 'push') { @@ -77,16 +86,6 @@ export const post: RequestHandler = async (event) => { }; } } else if (objectKind === 'merge_request') { - const webhookToken = event.request.headers.get('x-gitlab-token'); - if (!webhookToken) { - return { - status: 500, - body: { - message: 'Ooops, something is not okay, are you okay?' - } - }; - } - const isDraft = body.object_attributes.work_in_progress; const action = body.object_attributes.action; const projectId = Number(body.project.id);