@@ -2793,7 +2793,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2793
2793
} catch ( err ) {
2794
2794
throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "Clone URL must be a valid URL." ) ;
2795
2795
}
2796
- const canCreateProject = await this . projectsService . canCreateProject ( user , params . cloneUrl ) ;
2796
+ const canCreateProject = await this . canCreateProject ( user , params . cloneUrl ) ;
2797
2797
if ( ! canCreateProject ) {
2798
2798
throw new ApplicationError (
2799
2799
ErrorCodes . BAD_REQUEST ,
@@ -2823,6 +2823,35 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2823
2823
return project ;
2824
2824
}
2825
2825
2826
+ /**
2827
+ * Checks if a project can be created, i.e. the current user has the required permissions
2828
+ * at the given git provider.
2829
+ */
2830
+ private async canCreateProject ( currentUser : User , cloneURL : string ) {
2831
+ try {
2832
+ const parsedUrl = RepoURL . parseRepoUrl ( cloneURL ) ;
2833
+ const host = parsedUrl ?. host ;
2834
+ if ( ! host ) {
2835
+ throw Error ( "Unknown host: " + parsedUrl ?. host ) ;
2836
+ }
2837
+ if ( host === "github.com" && this . config . githubApp ?. enabled ) {
2838
+ const availableRepositories = await this . githubAppSupport . getProviderRepositoriesForUser ( {
2839
+ user : currentUser ,
2840
+ provider : "github.com" ,
2841
+ } ) ;
2842
+ return availableRepositories . some ( ( r ) => r . cloneUrl === cloneURL ) ;
2843
+ } else {
2844
+ return await this . projectsService . canCreateProject ( currentUser , cloneURL ) ;
2845
+
2846
+ // note: the GitHub App based check is not included in the ProjectService due
2847
+ // to a circular dependency problem which would otherwise occur.
2848
+ }
2849
+ } catch ( error ) {
2850
+ log . error ( "Failed to check precondition for creating a project." ) ;
2851
+ }
2852
+ return false ;
2853
+ }
2854
+
2826
2855
public async updateProjectPartial ( ctx : TraceContext , partialProject : PartialProject ) : Promise < void > {
2827
2856
traceAPIParams ( ctx , {
2828
2857
// censor everything irrelevant
0 commit comments