Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: handle forked repositories

Andras Bacsai8dbcf257c45d
diff --git a/apps/api/prisma/migrations/20221002091630_forked_previews/migration.sql b/apps/api/prisma/migrations/20221002091630_forked_previews/migration.sql
new file mode 100644
index 0000000000..2312c011bb
--- /dev/null
+++ b/apps/api/prisma/migrations/20221002091630_forked_previews/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Build" ADD COLUMN "sourceRepository" TEXT;
diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma
index d70f525447..eba0ac2153 100644
--- a/apps/api/prisma/schema.prisma
+++ b/apps/api/prisma/schema.prisma
@@ -247,6 +247,7 @@ model Build {
previewApplicationId String?
forceRebuild Boolean @default(false)
sourceBranch String?
+ sourceRepository String?
branch String?
status String? @default("queued")
createdAt DateTime @default(now())
diff --git a/apps/api/src/jobs/deployApplication.ts b/apps/api/src/jobs/deployApplication.ts
index ba0281b020..a2790aadbb 100644
--- a/apps/api/src/jobs/deployApplication.ts
+++ b/apps/api/src/jobs/deployApplication.ts
@@ -38,7 +38,7 @@ import * as buildpacks from '../lib/buildPacks';
for (const queueBuild of queuedBuilds) {
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 { 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)
const originalApplicationId = application.id
if (pullmergeRequestId) {
@@ -54,7 +54,6 @@ import * as buildpacks from '../lib/buildPacks';
}
const {
id: applicationId,
- repository,
name,
destinationDocker,
destinationDockerId,
@@ -77,6 +76,7 @@ import * as buildpacks from '../lib/buildPacks';
} = application
let {
branch,
+ repository,
buildPack,
port,
installCommand,
@@ -135,6 +135,7 @@ import * as buildpacks from '../lib/buildPacks';
branch = sourceBranch;
domain = `${pullmergeRequestId}.${domain}`;
imageId = `${applicationId}-${pullmergeRequestId}`;
+ repository = sourceRepository || repository;
}
let deployNeeded = true;
diff --git a/apps/api/src/routes/webhooks/github/handlers.ts b/apps/api/src/routes/webhooks/github/handlers.ts
index 8e8974553b..9c52a01afe 100644
--- a/apps/api/src/routes/webhooks/github/handlers.ts
+++ b/apps/api/src/routes/webhooks/github/handlers.ts
@@ -148,7 +148,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
const pullmergeRequestId = body.number.toString();
const pullmergeRequestAction = body.action;
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)) {
throw { status: 500, message: 'Action not allowed.' }
}
@@ -186,6 +186,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
data: {
pullmergeRequestId,
sourceBranch,
+ sourceRepository,
customDomain: `${protocol}${pullmergeRequestId}.${getDomain(application.fqdn)}`,
application: { connect: { id: application.id } }
}
@@ -206,6 +207,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
await prisma.build.create({
data: {
id: buildId,
+ sourceRepository,
pullmergeRequestId,
previewApplicationId,
sourceBranch,