fix: pr webhook
This commit is contained in:
@@ -75,16 +75,14 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
|||||||
if (!allowedGithubEvents.includes(githubEvent)) {
|
if (!allowedGithubEvents.includes(githubEvent)) {
|
||||||
throw { status: 500, message: 'Event not allowed.' }
|
throw { status: 500, message: 'Event not allowed.' }
|
||||||
}
|
}
|
||||||
let repository, projectId, branch;
|
let projectId, branch;
|
||||||
const body = request.body
|
const body = request.body
|
||||||
if (githubEvent === 'push') {
|
if (githubEvent === 'push') {
|
||||||
repository = body.repository;
|
projectId = body.repository.id;
|
||||||
projectId = repository.id;
|
|
||||||
branch = body.ref.includes('/') ? body.ref.split('/')[2] : body.ref;
|
branch = body.ref.includes('/') ? body.ref.split('/')[2] : body.ref;
|
||||||
} else if (githubEvent === 'pull_request') {
|
} else if (githubEvent === 'pull_request') {
|
||||||
repository = body.pull_request.head.repo;
|
projectId = body.pull_request.base.repo.id;
|
||||||
projectId = repository.id;
|
branch = body.pull_request.base.ref.includes('/') ? body.pull_request.base.ref.split('/')[2] : body.pull_request.base.ref;
|
||||||
branch = body.pull_request.head.ref.includes('/') ? body.pull_request.head.ref.split('/')[2] : body.pull_request.head.ref;
|
|
||||||
}
|
}
|
||||||
if (!projectId || !branch) {
|
if (!projectId || !branch) {
|
||||||
throw { status: 500, message: 'Cannot parse projectId or branch from the webhook?!' }
|
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') {
|
} else if (githubEvent === 'pull_request') {
|
||||||
const pullmergeRequestId = body.number;
|
const pullmergeRequestId = body.number;
|
||||||
const pullmergeRequestAction = body.action;
|
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)) {
|
if (!allowedActions.includes(pullmergeRequestAction)) {
|
||||||
throw { status: 500, message: 'Action not allowed.' }
|
throw { status: 500, message: 'Action not allowed.' }
|
||||||
}
|
}
|
||||||
|
@@ -8,12 +8,16 @@ export interface GitHubEvents {
|
|||||||
Body: {
|
Body: {
|
||||||
number: string,
|
number: string,
|
||||||
action: string,
|
action: string,
|
||||||
repository: string,
|
repository: {
|
||||||
|
id: string,
|
||||||
|
},
|
||||||
ref: string,
|
ref: string,
|
||||||
pull_request: {
|
pull_request: {
|
||||||
head: {
|
base: {
|
||||||
ref: string,
|
ref: string,
|
||||||
repo: string
|
repo: {
|
||||||
|
id: string,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user