fix: GitHub sync PR's
This commit is contained in:
parent
7bfa68aa58
commit
0eb7c890ad
@ -5,6 +5,7 @@ import cuid from 'cuid';
|
||||
import crypto from 'crypto';
|
||||
import { buildQueue } from '$lib/queues';
|
||||
import { checkContainer, removeProxyConfiguration } from '$lib/haproxy';
|
||||
import { dev } from '$app/env';
|
||||
|
||||
export const options: RequestHandler = async () => {
|
||||
return {
|
||||
@ -22,8 +23,8 @@ export const post: RequestHandler = async (event) => {
|
||||
const buildId = cuid();
|
||||
const allowedGithubEvents = ['push', 'pull_request'];
|
||||
const allowedActions = ['opened', 'reopened', 'synchronize', 'closed'];
|
||||
const githubEvent = event.request.headers.get('x-github-event').toLowerCase();
|
||||
const githubSignature = event.request.headers.get('x-hub-signature-256').toLowerCase();
|
||||
const githubEvent = event.request.headers.get('x-github-event')?.toLowerCase();
|
||||
const githubSignature = event.request.headers.get('x-hub-signature-256')?.toLowerCase();
|
||||
if (!allowedGithubEvents.includes(githubEvent)) {
|
||||
return {
|
||||
status: 500,
|
||||
@ -34,7 +35,6 @@ export const post: RequestHandler = async (event) => {
|
||||
}
|
||||
let repository, projectId, branch;
|
||||
const body = await event.request.json();
|
||||
|
||||
if (githubEvent === 'push') {
|
||||
repository = body.repository;
|
||||
projectId = repository.id;
|
||||
@ -54,6 +54,7 @@ export const post: RequestHandler = async (event) => {
|
||||
'utf8'
|
||||
);
|
||||
const checksum = Buffer.from(githubSignature, 'utf8');
|
||||
if (!dev) {
|
||||
if (checksum.length !== digest.length || !crypto.timingSafeEqual(digest, checksum)) {
|
||||
return {
|
||||
status: 500,
|
||||
@ -62,6 +63,8 @@ export const post: RequestHandler = async (event) => {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (githubEvent === 'push') {
|
||||
if (!applicationFound.configHash) {
|
||||
const configHash = crypto
|
||||
@ -120,7 +123,11 @@ export const post: RequestHandler = async (event) => {
|
||||
};
|
||||
}
|
||||
}
|
||||
if (pullmergeRequestAction === 'opened' || pullmergeRequestAction === 'reopened') {
|
||||
if (
|
||||
pullmergeRequestAction === 'opened' ||
|
||||
pullmergeRequestAction === 'reopened' ||
|
||||
pullmergeRequestAction === 'synchronize'
|
||||
) {
|
||||
await buildQueue.add(buildId, {
|
||||
build_id: buildId,
|
||||
type: 'webhook_pr',
|
||||
|
Loading…
x
Reference in New Issue
Block a user