fix: fork pr previews

This commit is contained in:
Andras Bacsai
2022-10-03 09:48:47 +02:00
parent 755eeda364
commit 9a67cf7355
5 changed files with 9 additions and 7 deletions

View File

@@ -23,6 +23,7 @@ export interface GitHubEvents {
ref: string,
repo: {
id: string,
full_name: string,
}
}
}

View File

@@ -39,9 +39,7 @@ export async function configureGitLabApp(request: FastifyRequest<ConfigureGitLab
export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
const { object_kind: objectKind, ref, project_id } = request.body
try {
const allowedActions = ['opened', 'reopen', 'close', 'open', 'update'];
const webhookToken = request.headers['x-gitlab-token'];
if (!webhookToken && !isDev) {
throw { status: 500, message: 'Invalid webhookToken.' }
@@ -91,7 +89,7 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
}
}
} else if (objectKind === 'merge_request') {
const { object_attributes: { work_in_progress: isDraft, action, source_branch: sourceBranch, target_branch: targetBranch }, project: { id } } = request.body
const { object_attributes: { work_in_progress: isDraft, action, source_branch: sourceBranch, target_branch: targetBranch, source: { path_with_namespace: sourceRepository } }, project: { id } } = request.body
const pullmergeRequestId = request.body.object_attributes.iid.toString();
const projectId = Number(id);
if (!allowedActions.includes(action)) {
@@ -100,7 +98,6 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
if (isDraft) {
throw { status: 500, message: 'Draft MR, do nothing.' }
}
const applicationsFound = await getApplicationFromDBWebhook(projectId, targetBranch);
if (applicationsFound && applicationsFound.length > 0) {
for (const application of applicationsFound) {
@@ -153,6 +150,7 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
id: buildId,
pullmergeRequestId,
previewApplicationId,
sourceRepository,
sourceBranch,
applicationId: application.id,
destinationDockerId: application.destinationDocker.id,

View File

@@ -8,6 +8,9 @@ export interface GitLabEvents {
Body: {
object_attributes: {
work_in_progress: string
source: {
path_with_namespace: string
}
isDraft: string
action: string
source_branch: string