@@ -2643,7 +2643,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2643
2643
} catch ( err ) {
2644
2644
throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "Clone URL must be a valid URL." ) ;
2645
2645
}
2646
- const canCreateProject = await this . projectsService . canCreateProject ( user , params . cloneUrl ) ;
2646
+ const canCreateProject = await this . canCreateProject ( user , params . cloneUrl ) ;
2647
2647
if ( ! canCreateProject ) {
2648
2648
throw new ApplicationError (
2649
2649
ErrorCodes . BAD_REQUEST ,
@@ -2673,6 +2673,35 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2673
2673
return project ;
2674
2674
}
2675
2675
2676
+ /**
2677
+ * Checks if a project can be created, i.e. the current user has the required permissions
2678
+ * at the given git provider.
2679
+ */
2680
+ private async canCreateProject ( currentUser : User , cloneURL : string ) {
2681
+ try {
2682
+ const parsedUrl = RepoURL . parseRepoUrl ( cloneURL ) ;
2683
+ const host = parsedUrl ?. host ;
2684
+ if ( ! host ) {
2685
+ throw Error ( "Unknown host: " + parsedUrl ?. host ) ;
2686
+ }
2687
+ if ( host === "github.com" && this . config . githubApp ?. enabled ) {
2688
+ const availableRepositories = await this . githubAppSupport . getProviderRepositoriesForUser ( {
2689
+ user : currentUser ,
2690
+ provider : "github.com" ,
2691
+ } ) ;
2692
+ return availableRepositories . some ( ( r ) => r . cloneUrl === cloneURL ) ;
2693
+ } else {
2694
+ return await this . projectsService . canCreateProject ( currentUser , cloneURL ) ;
2695
+
2696
+ // note: the GitHub App based check is not included in the ProjectService due
2697
+ // to a circular dependency problem which would otherwise occur.
2698
+ }
2699
+ } catch ( error ) {
2700
+ log . error ( "Failed to check precondition for creating a project." ) ;
2701
+ }
2702
+ return false ;
2703
+ }
2704
+
2676
2705
public async updateProjectPartial ( ctx : TraceContext , partialProject : PartialProject ) : Promise < void > {
2677
2706
traceAPIParams ( ctx , {
2678
2707
// censor everything irrelevant
0 commit comments