fix: webhook
This commit is contained in:
parent
e47395bab7
commit
2e7c96b2eb
@ -177,7 +177,6 @@ export async function getApplicationFromDB(id: string, teamId: string) {
|
|||||||
}
|
}
|
||||||
export async function getApplicationFromDBWebhook(projectId: number, branch: string) {
|
export async function getApplicationFromDBWebhook(projectId: number, branch: string) {
|
||||||
try {
|
try {
|
||||||
console.log({ projectId, branch })
|
|
||||||
let application = await prisma.application.findFirst({
|
let application = await prisma.application.findFirst({
|
||||||
where: { projectId, branch, settings: { autodeploy: true } },
|
where: { projectId, branch, settings: { autodeploy: true } },
|
||||||
include: {
|
include: {
|
||||||
@ -188,7 +187,6 @@ export async function getApplicationFromDBWebhook(projectId: number, branch: str
|
|||||||
persistentStorage: true
|
persistentStorage: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log({ application })
|
|
||||||
if (!application) {
|
if (!application) {
|
||||||
throw { status: 500, message: 'Application not configured.' }
|
throw { status: 500, message: 'Application not configured.' }
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,15 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
|||||||
if (githubEvent === 'push') {
|
if (githubEvent === 'push') {
|
||||||
repository = body.repository;
|
repository = body.repository;
|
||||||
projectId = repository.id;
|
projectId = repository.id;
|
||||||
branch = body.ref.split('/')[2];
|
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;
|
repository = body.pull_request.head.repo;
|
||||||
projectId = repository.id;
|
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);
|
const applicationFound = await getApplicationFromDBWebhook(projectId, branch);
|
||||||
if (applicationFound) {
|
if (applicationFound) {
|
||||||
const webhookSecret = applicationFound.gitSource.githubApp.webhookSecret || null;
|
const webhookSecret = applicationFound.gitSource.githubApp.webhookSecret || null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user