@@ -14,14 +14,19 @@ export default class ProjectsAdd extends Command {
1414 description : 'domain name where the app will be served, e.g. www.example.com' ,
1515 } ) ,
1616 github : Flags . string ( {
17- required : false ,
17+ required : true ,
1818 description :
1919 'full name of the Github repository, including user or organization and repository name, e.g. myuser/myproject' ,
2020 } ) ,
2121 branch : Flags . string ( {
2222 required : false ,
2323 description : 'the branch of the repository to use' ,
2424 } ) ,
25+ deployPublicRepo : Flags . boolean ( {
26+ required : false ,
27+ description :
28+ 'deploy a public repository without checking for GitHub access. Note that "git push" to the repo will not trigger a new deployment' ,
29+ } ) ,
2530 disco : Flags . string ( { required : false , description : 'server to use' } ) ,
2631 }
2732
@@ -33,6 +38,14 @@ export default class ProjectsAdd extends Command {
3338 }
3439
3540 const discoConfig = getDisco ( flags . disco || null )
41+
42+ if ( ! flags . deployPublicRepo && ! ( await isGithubRepoAuthorized ( discoConfig , flags . github ) ) ) {
43+ this . error ( `disco does not have access to this GitHub repository.
44+
45+ Either set up GitHub access by running "disco github:apps:add"
46+ or edit your GitHub repo permissions by running "disco github:apps:manage <your github username>".` )
47+ }
48+
3649 const url = `https://${ discoConfig . host } /api/projects`
3750
3851 const body = {
@@ -60,3 +73,14 @@ export default class ProjectsAdd extends Command {
6073 }
6174 }
6275}
76+
77+ async function isGithubRepoAuthorized ( discoConfig : any , repoBeingChecked : string ) {
78+ // check if the user has access to the github repo
79+ const url = `https://${ discoConfig . host } /api/github-app-repos`
80+
81+ const res = await request ( { method : 'GET' , url, discoConfig} )
82+ const data = ( await res . json ( ) ) as any
83+
84+ const authorizedRepos = data . repos . map ( ( r : any ) => r . fullName )
85+ return authorizedRepos . includes ( repoBeingChecked )
86+ }
0 commit comments