@@ -15,12 +15,7 @@ import {
1515
1616export async function cancelBuild ( buildId : string ) {
1717 await requireDeveloperRole ( ) ;
18- const [ result ] = await db
19- . select ( { build : builds } )
20- . from ( builds )
21- . innerJoin ( services , eq ( services . id , builds . serviceId ) )
22- . where ( and ( eq ( builds . id , buildId ) , isNull ( services . previewOfServiceId ) ) ) ;
23- const build = result ?. build ;
18+ const [ build ] = await db . select ( ) . from ( builds ) . where ( eq ( builds . id , buildId ) ) ;
2419
2520 if ( ! build ) {
2621 throw new Error ( "Build not found" ) ;
@@ -89,15 +84,12 @@ export async function retryBuild(buildId: string) {
8984 }
9085
9186 const [ service ] = await db
92- . select ( { id : services . id } )
87+ . select ( {
88+ id : services . id ,
89+ previewOfService : services . previewOfService ,
90+ } )
9391 . from ( services )
94- . where (
95- and (
96- eq ( services . id , build . serviceId ) ,
97- isNull ( services . deletedAt ) ,
98- isNull ( services . previewOfServiceId ) ,
99- ) ,
100- ) ;
92+ . where ( and ( eq ( services . id , build . serviceId ) , isNull ( services . deletedAt ) ) ) ;
10193
10294 if ( ! service ) {
10395 throw new Error ( "Service not found" ) ;
@@ -107,16 +99,22 @@ export async function retryBuild(buildId: string) {
10799 throw new Error ( `Cannot retry build in ${ build . status } status` ) ;
108100 }
109101
102+ const actor = {
103+ type : "user" as const ,
104+ userId : session . user . id ,
105+ name : session . user . name ,
106+ } ;
107+ if ( service . previewOfService ) {
108+ await triggerBuildInternal ( build . serviceId , "manual" , actor ) ;
109+ return { success : true } ;
110+ }
111+
110112 await requeueBuildRevisionInternal ( {
111113 serviceId : build . serviceId ,
112114 serviceRevisionId : build . serviceRevisionId ,
113115 commitMessage : build . commitMessage ?? "Retry build" ,
114116 author : build . author ?? undefined ,
115- actor : {
116- type : "user" ,
117- userId : session . user . id ,
118- name : session . user . name ,
119- } ,
117+ actor,
120118 } ) ;
121119
122120 return { success : true } ;
@@ -127,18 +125,6 @@ export async function triggerBuild(
127125 trigger : "manual" | "scheduled" = "manual" ,
128126) {
129127 const session = await requireDeveloperRole ( ) ;
130- const service = await db
131- . select ( { id : services . id } )
132- . from ( services )
133- . where (
134- and (
135- eq ( services . id , serviceId ) ,
136- isNull ( services . deletedAt ) ,
137- isNull ( services . previewOfServiceId ) ,
138- ) ,
139- )
140- . then ( ( rows ) => rows [ 0 ] ) ;
141- if ( ! service ) throw new Error ( "Service not found" ) ;
142128 const actor = session
143129 ? {
144130 type : "user" as const ,
@@ -162,17 +148,16 @@ export async function triggerManualBuild(serviceId: string, commitSha: string) {
162148 . select ( { service : services , githubRepo : githubRepos } )
163149 . from ( services )
164150 . innerJoin ( githubRepos , eq ( githubRepos . serviceId , services . id ) )
165- . where (
166- and (
167- eq ( services . id , serviceId ) ,
168- isNull ( services . deletedAt ) ,
169- isNull ( services . previewOfServiceId ) ,
170- ) ,
171- ) ;
151+ . where ( and ( eq ( services . id , serviceId ) , isNull ( services . deletedAt ) ) ) ;
172152 if ( ! result ) throw new Error ( "Active GitHub App-connected service not found" ) ;
173153 if ( result . service . sourceType !== "github" ) {
174154 throw new Error ( "Service is not connected to GitHub" ) ;
175155 }
156+ if ( result . service . previewOfService ) {
157+ throw new Error (
158+ "Preview services build their pull request merge ref; use Build to rebuild it" ,
159+ ) ;
160+ }
176161
177162 const branch =
178163 result . githubRepo . deployBranch || result . githubRepo . defaultBranch || "main" ;
0 commit comments