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? | ||||
|   forceRebuild         Boolean  @default(false) | ||||
|   sourceBranch         String? | ||||
|   sourceRepository     String? | ||||
|   branch               String? | ||||
|   status               String?  @default("queued") | ||||
|   createdAt            DateTime @default(now()) | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
| @ -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, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user