fix: pr webhook

This commit is contained in:
Andras Bacsai 2022-07-25 19:42:58 +00:00
parent 097d7b547a
commit 8645d954dd
2 changed files with 12 additions and 10 deletions

View File

@ -75,16 +75,14 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
if (!allowedGithubEvents.includes(githubEvent)) {
throw { status: 500, message: 'Event not allowed.' }
}
let repository, projectId, branch;
let projectId, branch;
const body = request.body
if (githubEvent === 'push') {
repository = body.repository;
projectId = repository.id;
projectId = body.repository.id;
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.includes('/') ? body.pull_request.head.ref.split('/')[2] : body.pull_request.head.ref;
projectId = body.pull_request.base.repo.id;
branch = body.pull_request.base.ref.includes('/') ? body.pull_request.base.ref.split('/')[2] : body.pull_request.base.ref;
}
if (!projectId || !branch) {
throw { status: 500, message: 'Cannot parse projectId or branch from the webhook?!' }
@ -156,7 +154,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
} else if (githubEvent === 'pull_request') {
const pullmergeRequestId = body.number;
const pullmergeRequestAction = body.action;
const sourceBranch = body.pull_request.head.ref;
const sourceBranch = body.pull_request.base.ref.includes('/') ? body.pull_request.base.ref.split('/')[2] : body.pull_request.base.ref;
if (!allowedActions.includes(pullmergeRequestAction)) {
throw { status: 500, message: 'Action not allowed.' }
}

View File

@ -8,12 +8,16 @@ export interface GitHubEvents {
Body: {
number: string,
action: string,
repository: string,
repository: {
id: string,
},
ref: string,
pull_request: {
head: {
base: {
ref: string,
repo: string
repo: {
id: string,
}
}
}
}