@@ -19,23 +19,23 @@ import { HostContextProvider } from "../auth/host-context-provider";
19
19
import { RepoURL } from "../repohost" ;
20
20
import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
21
21
import { PartialProject } from "@gitpod/gitpod-protocol/lib/teams-projects-protocol" ;
22
- import { Config } from "../config" ;
23
22
import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics" ;
24
23
import { ErrorCodes , ApplicationError } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
25
24
import { URL } from "url" ;
26
25
import { Authorizer } from "../authorization/authorizer" ;
27
26
import { TransactionalContext } from "@gitpod/gitpod-db/lib/typeorm/transactional-db-impl" ;
27
+ import { ScmService } from "./scm-service" ;
28
28
29
29
@injectable ( )
30
30
export class ProjectsService {
31
31
constructor (
32
32
@inject ( ProjectDB ) private readonly projectDB : ProjectDB ,
33
33
@inject ( TracedWorkspaceDB ) private readonly workspaceDb : DBWithTracing < WorkspaceDB > ,
34
34
@inject ( HostContextProvider ) private readonly hostContextProvider : HostContextProvider ,
35
- @inject ( Config ) private readonly config : Config ,
36
35
@inject ( IAnalyticsWriter ) private readonly analytics : IAnalyticsWriter ,
37
36
@inject ( WebhookEventDB ) private readonly webhookEventDB : WebhookEventDB ,
38
37
@inject ( Authorizer ) private readonly auth : Authorizer ,
38
+ @inject ( ScmService ) private readonly scmService : ScmService ,
39
39
) { }
40
40
41
41
async getProject ( userId : string , projectId : string ) : Promise < Project > {
@@ -193,34 +193,6 @@ export class ProjectsService {
193
193
return result ;
194
194
}
195
195
196
- async canCreateProject ( currentUser : User , cloneURL : string ) {
197
- try {
198
- const parsedUrl = RepoURL . parseRepoUrl ( cloneURL ) ;
199
- const hostContext = parsedUrl ?. host ? this . hostContextProvider . get ( parsedUrl ?. host ) : undefined ;
200
- const authProvider = hostContext && hostContext . authProvider . info ;
201
- const type = authProvider && authProvider . authProviderType ;
202
- const host = authProvider ?. host ;
203
- if ( ! type || ! host ) {
204
- throw Error ( "Unknown host: " + parsedUrl ?. host ) ;
205
- }
206
- if (
207
- type === "GitLab" ||
208
- type === "Bitbucket" ||
209
- type === "BitbucketServer" ||
210
- ( type === "GitHub" && ( host !== "github.com" || ! this . config . githubApp ?. enabled ) )
211
- ) {
212
- const repositoryService = hostContext ?. services ?. repositoryService ;
213
- if ( repositoryService ) {
214
- return await repositoryService . canInstallAutomatedPrebuilds ( currentUser , cloneURL ) ;
215
- }
216
- }
217
- // The GitHub App case isn't handled here due to a circular dependency problem.
218
- } catch ( error ) {
219
- log . error ( "Failed to check precondition for creating a project." ) ;
220
- }
221
- return false ;
222
- }
223
-
224
196
async createProject (
225
197
{ name, slug, cloneUrl, teamId, appInstallationId } : CreateProjectParams ,
226
198
installer : User ,
@@ -272,7 +244,12 @@ export class ProjectsService {
272
244
await this . auth . removeProjectFromOrg ( installer . id , teamId , project . id ) ;
273
245
throw err ;
274
246
}
275
- await this . onDidCreateProject ( project , installer ) ;
247
+ await this . scmService . installWebhookForPrebuilds ( project , installer ) ;
248
+
249
+ // Pre-fetch project details in the background -- don't await
250
+ this . getProjectOverview ( installer , project . id ) . catch ( ( err ) => {
251
+ log . error ( `Error pre-fetching project details for project ${ project . id } : ${ err } ` ) ;
252
+ } ) ;
276
253
277
254
this . analytics . track ( {
278
255
userId : installer . id ,
@@ -289,40 +266,6 @@ export class ProjectsService {
289
266
return project ;
290
267
}
291
268
292
- private async onDidCreateProject ( project : Project , installer : User ) {
293
- // Pre-fetch project details in the background -- don't await
294
- this . getProjectOverview ( installer , project . id ) . catch ( ( err ) => {
295
- log . error ( `Error pre-fetching project details for project ${ project . id } : ${ err } ` ) ;
296
- } ) ;
297
-
298
- // Install the prebuilds webhook if possible
299
- const { teamId, cloneUrl } = project ;
300
- const parsedUrl = RepoURL . parseRepoUrl ( project . cloneUrl ) ;
301
- const hostContext = parsedUrl ?. host ? this . hostContextProvider . get ( parsedUrl ?. host ) : undefined ;
302
- const authProvider = hostContext && hostContext . authProvider . info ;
303
- const type = authProvider && authProvider . authProviderType ;
304
- if (
305
- type === "GitLab" ||
306
- type === "Bitbucket" ||
307
- type === "BitbucketServer" ||
308
- ( type === "GitHub" && ( authProvider ?. host !== "github.com" || ! this . config . githubApp ?. enabled ) )
309
- ) {
310
- const repositoryService = hostContext ?. services ?. repositoryService ;
311
- if ( repositoryService ) {
312
- // Note: For GitLab, we expect .canInstallAutomatedPrebuilds() to always return true, because earlier
313
- // in the project creation flow, we only propose repositories where the user is actually allowed to
314
- // install a webhook.
315
- if ( await repositoryService . canInstallAutomatedPrebuilds ( installer , cloneUrl ) ) {
316
- log . info (
317
- { organizationId : teamId , userId : installer . id } ,
318
- "Update prebuild installation for project." ,
319
- ) ;
320
- await repositoryService . installAutomatedPrebuilds ( installer , cloneUrl ) ;
321
- }
322
- }
323
- }
324
- }
325
-
326
269
async deleteProject ( userId : string , projectId : string , transactionCtx ?: TransactionalContext ) : Promise < void > {
327
270
await this . auth . checkPermissionOnProject ( userId , "delete" , projectId ) ;
328
271
0 commit comments