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