66 "path"
77 "strings"
88
9+ "github.com/cli/cli/api"
910 "github.com/cli/cli/git"
1011 "github.com/cli/cli/internal/ghrepo"
1112 "github.com/cli/cli/utils"
@@ -16,6 +17,10 @@ func init() {
1617 RootCmd .AddCommand (repoCmd )
1718 repoCmd .AddCommand (repoCloneCmd )
1819 repoCmd .AddCommand (repoCreateCmd )
20+ repoCreateCmd .Flags ().StringP ("description" , "d" , "" , "Description of repository" )
21+ repoCreateCmd .Flags ().StringP ("homepage" , "h" , "" , "Repository home page URL" )
22+ repoCreateCmd .Flags ().Bool ("enable-issues" , true , "Enable issues in the new repository" )
23+ repoCreateCmd .Flags ().Bool ("enable-wiki" , true , "Enable wiki in the new repository" )
1924 repoCreateCmd .Flags ().Bool ("public" , false , "Make the new repository public" )
2025 repoCmd .AddCommand (repoViewCmd )
2126}
@@ -85,46 +90,54 @@ func repoCreate(cmd *cobra.Command, args []string) error {
8590 name = path .Base (dir )
8691 }
8792
88- visibility := "PRIVATE"
89- if isPublic , err := cmd . Flags (). GetBool ( "public" ); err == nil && isPublic {
90- visibility = "PUBLIC"
93+ isPublic , err := cmd . Flags (). GetBool ( "public" )
94+ if err != nil {
95+ return err
9196 }
92-
93- ctx := contextForCommand (cmd )
94- client , err := apiClientForContext (ctx )
97+ hasIssuesEnabled , err := cmd .Flags ().GetBool ("enable-issues" )
98+ if err != nil {
99+ return err
100+ }
101+ hasWikiEnabled , err := cmd .Flags ().GetBool ("enable-wiki" )
102+ if err != nil {
103+ return err
104+ }
105+ description , err := cmd .Flags ().GetString ("description" )
106+ if err != nil {
107+ return err
108+ }
109+ homepage , err := cmd .Flags ().GetString ("homepage" )
95110 if err != nil {
96111 return err
97112 }
98113
99- variables := map [string ]interface {}{
100- "input" : map [string ]interface {}{
101- "name" : name ,
102- "visibility" : visibility ,
103- },
114+ // TODO: move this into constant within `api`
115+ visibility := "PRIVATE"
116+ if isPublic {
117+ visibility = "PUBLIC"
104118 }
105119
106- var response struct {
107- CreateRepository struct {
108- Repository struct {
109- URL string
110- }
111- }
120+ input := api.RepoCreateInput {
121+ Name : name ,
122+ Visibility : visibility ,
123+ Description : description ,
124+ Homepage : homepage ,
125+ HasIssuesEnabled : hasIssuesEnabled ,
126+ HasWikiEnabled : hasWikiEnabled ,
112127 }
113128
114- err = client .GraphQL (`
115- mutation($input: CreateRepositoryInput!) {
116- createRepository(input: $input) {
117- repository {
118- url
119- }
120- }
129+ ctx := contextForCommand (cmd )
130+ client , err := apiClientForContext (ctx )
131+ if err != nil {
132+ return err
121133 }
122- ` , variables , & response )
134+
135+ repo , err := api .RepoCreate (client , input )
123136 if err != nil {
124137 return err
125138 }
126139
127- cmd . Println ( response . CreateRepository . Repository .URL )
140+ fmt . Fprintln ( cmd . OutOrStdout (), repo .URL )
128141 return nil
129142}
130143
0 commit comments