From 2e7c96b2eb266b68b400361934ab534d943a1e4b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 25 Jul 2022 11:18:19 +0000 Subject: [PATCH] fix: webhook --- apps/api/src/routes/api/v1/applications/handlers.ts | 2 -- apps/api/src/routes/webhooks/github/handlers.ts | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index 42b771601..5896422ca 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -177,7 +177,6 @@ export async function getApplicationFromDB(id: string, teamId: string) { } export async function getApplicationFromDBWebhook(projectId: number, branch: string) { try { - console.log({ projectId, branch }) let application = await prisma.application.findFirst({ where: { projectId, branch, settings: { autodeploy: true } }, include: { @@ -188,7 +187,6 @@ export async function getApplicationFromDBWebhook(projectId: number, branch: str persistentStorage: true } }); - console.log({ application }) if (!application) { throw { status: 500, message: 'Application not configured.' } } diff --git a/apps/api/src/routes/webhooks/github/handlers.ts b/apps/api/src/routes/webhooks/github/handlers.ts index cd6156236..401e37d33 100644 --- a/apps/api/src/routes/webhooks/github/handlers.ts +++ b/apps/api/src/routes/webhooks/github/handlers.ts @@ -80,13 +80,15 @@ export async function gitHubEvents(request: FastifyRequest): Promi if (githubEvent === 'push') { repository = body.repository; projectId = repository.id; - branch = body.ref.split('/')[2]; + branch = body.ref.includes('/') ? body.ref.split('/')[2] : body.ref; } else if (githubEvent === 'pull_request') { repository = body.pull_request.head.repo; projectId = repository.id; - branch = body.pull_request.head.ref.split('/')[2]; + branch = body.pull_request.head.ref.includes('/') ? body.pull_request.head.ref.split('/')[2] : body.pull_request.head.ref; + } + if (!projectId || !branch) { + throw { status: 500, message: 'Cannot parse projectId or branch from the webhook?!' } } - console.log({repository, projectId, branch}) const applicationFound = await getApplicationFromDBWebhook(projectId, branch); if (applicationFound) { const webhookSecret = applicationFound.gitSource.githubApp.webhookSecret || null;