fix: handle forked repositories
This commit is contained in:
parent
0b067364a9
commit
8dbcf257c4
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Build" ADD COLUMN "sourceRepository" TEXT;
|
||||||
@ -247,6 +247,7 @@ model Build {
|
|||||||
previewApplicationId String?
|
previewApplicationId String?
|
||||||
forceRebuild Boolean @default(false)
|
forceRebuild Boolean @default(false)
|
||||||
sourceBranch String?
|
sourceBranch String?
|
||||||
|
sourceRepository String?
|
||||||
branch String?
|
branch String?
|
||||||
status String? @default("queued")
|
status String? @default("queued")
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
for (const queueBuild of queuedBuilds) {
|
for (const queueBuild of queuedBuilds) {
|
||||||
actions.push(async () => {
|
actions.push(async () => {
|
||||||
let application = await prisma.application.findUnique({ where: { id: queueBuild.applicationId }, include: { destinationDocker: true, gitSource: { include: { githubApp: true, gitlabApp: true } }, persistentStorage: true, secrets: true, settings: true, teams: true } })
|
let application = await prisma.application.findUnique({ where: { id: queueBuild.applicationId }, include: { destinationDocker: true, gitSource: { include: { githubApp: true, gitlabApp: true } }, persistentStorage: true, secrets: true, settings: true, teams: true } })
|
||||||
let { id: buildId, type, sourceBranch = null, pullmergeRequestId = null, previewApplicationId = null, forceRebuild } = queueBuild
|
let { id: buildId, type, sourceBranch = null, pullmergeRequestId = null, previewApplicationId = null, forceRebuild, sourceRepository = null } = queueBuild
|
||||||
application = decryptApplication(application)
|
application = decryptApplication(application)
|
||||||
const originalApplicationId = application.id
|
const originalApplicationId = application.id
|
||||||
if (pullmergeRequestId) {
|
if (pullmergeRequestId) {
|
||||||
@ -54,7 +54,6 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
}
|
}
|
||||||
const {
|
const {
|
||||||
id: applicationId,
|
id: applicationId,
|
||||||
repository,
|
|
||||||
name,
|
name,
|
||||||
destinationDocker,
|
destinationDocker,
|
||||||
destinationDockerId,
|
destinationDockerId,
|
||||||
@ -77,6 +76,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
} = application
|
} = application
|
||||||
let {
|
let {
|
||||||
branch,
|
branch,
|
||||||
|
repository,
|
||||||
buildPack,
|
buildPack,
|
||||||
port,
|
port,
|
||||||
installCommand,
|
installCommand,
|
||||||
@ -135,6 +135,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
branch = sourceBranch;
|
branch = sourceBranch;
|
||||||
domain = `${pullmergeRequestId}.${domain}`;
|
domain = `${pullmergeRequestId}.${domain}`;
|
||||||
imageId = `${applicationId}-${pullmergeRequestId}`;
|
imageId = `${applicationId}-${pullmergeRequestId}`;
|
||||||
|
repository = sourceRepository || repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
let deployNeeded = true;
|
let deployNeeded = true;
|
||||||
|
|||||||
@ -148,7 +148,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
|||||||
const pullmergeRequestId = body.number.toString();
|
const pullmergeRequestId = body.number.toString();
|
||||||
const pullmergeRequestAction = body.action;
|
const pullmergeRequestAction = body.action;
|
||||||
const sourceBranch = body.pull_request.head.ref.includes('/') ? body.pull_request.head.ref.split('/')[2] : body.pull_request.head.ref;
|
const sourceBranch = body.pull_request.head.ref.includes('/') ? body.pull_request.head.ref.split('/')[2] : body.pull_request.head.ref;
|
||||||
console.log({sourceBranch, sourceRepository: body.pull_request.head.repo.full_name})
|
const sourceRepository = body.pull_request.head.repo.full_name
|
||||||
if (!allowedActions.includes(pullmergeRequestAction)) {
|
if (!allowedActions.includes(pullmergeRequestAction)) {
|
||||||
throw { status: 500, message: 'Action not allowed.' }
|
throw { status: 500, message: 'Action not allowed.' }
|
||||||
}
|
}
|
||||||
@ -186,6 +186,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
|||||||
data: {
|
data: {
|
||||||
pullmergeRequestId,
|
pullmergeRequestId,
|
||||||
sourceBranch,
|
sourceBranch,
|
||||||
|
sourceRepository,
|
||||||
customDomain: `${protocol}${pullmergeRequestId}.${getDomain(application.fqdn)}`,
|
customDomain: `${protocol}${pullmergeRequestId}.${getDomain(application.fqdn)}`,
|
||||||
application: { connect: { id: application.id } }
|
application: { connect: { id: application.id } }
|
||||||
}
|
}
|
||||||
@ -206,6 +207,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
|||||||
await prisma.build.create({
|
await prisma.build.create({
|
||||||
data: {
|
data: {
|
||||||
id: buildId,
|
id: buildId,
|
||||||
|
sourceRepository,
|
||||||
pullmergeRequestId,
|
pullmergeRequestId,
|
||||||
previewApplicationId,
|
previewApplicationId,
|
||||||
sourceBranch,
|
sourceBranch,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user