add include-all-branches flag to repo create (#5537)
This commit is contained in:
parent
ff8aa8a555
commit
2918c538b3
4 changed files with 78 additions and 48 deletions
|
|
@ -27,24 +27,25 @@ type CreateOptions struct {
|
||||||
Config func() (config.Config, error)
|
Config func() (config.Config, error)
|
||||||
IO *iostreams.IOStreams
|
IO *iostreams.IOStreams
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Homepage string
|
Homepage string
|
||||||
Team string
|
Team string
|
||||||
Template string
|
Template string
|
||||||
Public bool
|
Public bool
|
||||||
Private bool
|
Private bool
|
||||||
Internal bool
|
Internal bool
|
||||||
Visibility string
|
Visibility string
|
||||||
Push bool
|
Push bool
|
||||||
Clone bool
|
Clone bool
|
||||||
Source string
|
Source string
|
||||||
Remote string
|
Remote string
|
||||||
GitIgnoreTemplate string
|
GitIgnoreTemplate string
|
||||||
LicenseTemplate string
|
LicenseTemplate string
|
||||||
DisableIssues bool
|
DisableIssues bool
|
||||||
DisableWiki bool
|
DisableWiki bool
|
||||||
Interactive bool
|
Interactive bool
|
||||||
|
IncludeAllBranches bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
|
func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
|
||||||
|
|
@ -144,6 +145,10 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
|
||||||
return cmdutil.FlagErrorf("the `--template` option is not supported with `--homepage`, `--team`, `--disable-issues`, or `--disable-wiki`")
|
return cmdutil.FlagErrorf("the `--template` option is not supported with `--homepage`, `--team`, `--disable-issues`, or `--disable-wiki`")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Template == "" && opts.IncludeAllBranches {
|
||||||
|
return cmdutil.FlagErrorf("the `--include-all-branches` option is only supported when using `--template`")
|
||||||
|
}
|
||||||
|
|
||||||
if runF != nil {
|
if runF != nil {
|
||||||
return runF(opts)
|
return runF(opts)
|
||||||
}
|
}
|
||||||
|
|
@ -166,6 +171,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
|
||||||
cmd.Flags().BoolVarP(&opts.Clone, "clone", "c", false, "Clone the new repository to the current directory")
|
cmd.Flags().BoolVarP(&opts.Clone, "clone", "c", false, "Clone the new repository to the current directory")
|
||||||
cmd.Flags().BoolVar(&opts.DisableIssues, "disable-issues", false, "Disable issues in the new repository")
|
cmd.Flags().BoolVar(&opts.DisableIssues, "disable-issues", false, "Disable issues in the new repository")
|
||||||
cmd.Flags().BoolVar(&opts.DisableWiki, "disable-wiki", false, "Disable wiki in the new repository")
|
cmd.Flags().BoolVar(&opts.DisableWiki, "disable-wiki", false, "Disable wiki in the new repository")
|
||||||
|
cmd.Flags().BoolVar(&opts.IncludeAllBranches, "include-all-branches", false, "Include all branches from template repository")
|
||||||
|
|
||||||
// deprecated flags
|
// deprecated flags
|
||||||
cmd.Flags().BoolP("confirm", "y", false, "Skip the confirmation prompt")
|
cmd.Flags().BoolP("confirm", "y", false, "Skip the confirmation prompt")
|
||||||
|
|
@ -295,16 +301,17 @@ func createFromScratch(opts *CreateOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
input := repoCreateInput{
|
input := repoCreateInput{
|
||||||
Name: repoToCreate.RepoName(),
|
Name: repoToCreate.RepoName(),
|
||||||
Visibility: opts.Visibility,
|
Visibility: opts.Visibility,
|
||||||
OwnerLogin: repoToCreate.RepoOwner(),
|
OwnerLogin: repoToCreate.RepoOwner(),
|
||||||
TeamSlug: opts.Team,
|
TeamSlug: opts.Team,
|
||||||
Description: opts.Description,
|
Description: opts.Description,
|
||||||
HomepageURL: opts.Homepage,
|
HomepageURL: opts.Homepage,
|
||||||
HasIssuesEnabled: !opts.DisableIssues,
|
HasIssuesEnabled: !opts.DisableIssues,
|
||||||
HasWikiEnabled: !opts.DisableWiki,
|
HasWikiEnabled: !opts.DisableWiki,
|
||||||
GitIgnoreTemplate: opts.GitIgnoreTemplate,
|
GitIgnoreTemplate: opts.GitIgnoreTemplate,
|
||||||
LicenseTemplate: opts.LicenseTemplate,
|
LicenseTemplate: opts.LicenseTemplate,
|
||||||
|
IncludeAllBranches: opts.IncludeAllBranches,
|
||||||
}
|
}
|
||||||
|
|
||||||
var templateRepoMainBranch string
|
var templateRepoMainBranch string
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,22 @@ func TestNewCmdCreate(t *testing.T) {
|
||||||
wantsErr: true,
|
wantsErr: true,
|
||||||
errMsg: "the `--source` option is not supported with `--clone`, `--template`, `--license`, or `--gitignore`",
|
errMsg: "the `--source` option is not supported with `--clone`, `--template`, `--license`, or `--gitignore`",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "include all branches without template",
|
||||||
|
cli: "--source=/path/to/repo --private --include-all-branches",
|
||||||
|
wantsErr: true,
|
||||||
|
errMsg: "the `--include-all-branches` option is only supported when using `--template`",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "new remote from template with include all branches",
|
||||||
|
cli: "template-repo --template https://github.com/OWNER/REPO --public --include-all-branches",
|
||||||
|
wantsOpts: CreateOptions{
|
||||||
|
Name: "template-repo",
|
||||||
|
Public: true,
|
||||||
|
Template: "https://github.com/OWNER/REPO",
|
||||||
|
IncludeAllBranches: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ type repoCreateInput struct {
|
||||||
HasWikiEnabled bool
|
HasWikiEnabled bool
|
||||||
GitIgnoreTemplate string
|
GitIgnoreTemplate string
|
||||||
LicenseTemplate string
|
LicenseTemplate string
|
||||||
|
IncludeAllBranches bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// createRepositoryInputV3 is the payload for the repo create REST API
|
// createRepositoryInputV3 is the payload for the repo create REST API
|
||||||
|
|
@ -53,11 +54,12 @@ type createRepositoryInput struct {
|
||||||
|
|
||||||
// cloneTemplateRepositoryInput is the payload for creating a repo from a template using GraphQL
|
// cloneTemplateRepositoryInput is the payload for creating a repo from a template using GraphQL
|
||||||
type cloneTemplateRepositoryInput struct {
|
type cloneTemplateRepositoryInput struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Visibility string `json:"visibility"`
|
Visibility string `json:"visibility"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
OwnerID string `json:"ownerId"`
|
OwnerID string `json:"ownerId"`
|
||||||
RepositoryID string `json:"repositoryId"`
|
RepositoryID string `json:"repositoryId"`
|
||||||
|
IncludeAllBranches bool `json:"includeAllBranches"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// repoCreate creates a new GitHub repository
|
// repoCreate creates a new GitHub repository
|
||||||
|
|
@ -104,11 +106,12 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a
|
||||||
|
|
||||||
variables := map[string]interface{}{
|
variables := map[string]interface{}{
|
||||||
"input": cloneTemplateRepositoryInput{
|
"input": cloneTemplateRepositoryInput{
|
||||||
Name: input.Name,
|
Name: input.Name,
|
||||||
Description: input.Description,
|
Description: input.Description,
|
||||||
Visibility: strings.ToUpper(input.Visibility),
|
Visibility: strings.ToUpper(input.Visibility),
|
||||||
OwnerID: ownerID,
|
OwnerID: ownerID,
|
||||||
RepositoryID: input.TemplateRepositoryID,
|
RepositoryID: input.TemplateRepositoryID,
|
||||||
|
IncludeAllBranches: input.IncludeAllBranches,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,7 @@ func Test_repoCreate(t *testing.T) {
|
||||||
TemplateRepositoryID: "TPLID",
|
TemplateRepositoryID: "TPLID",
|
||||||
HasIssuesEnabled: true,
|
HasIssuesEnabled: true,
|
||||||
HasWikiEnabled: true,
|
HasWikiEnabled: true,
|
||||||
|
IncludeAllBranches: false,
|
||||||
},
|
},
|
||||||
stubs: func(t *testing.T, r *httpmock.Registry) {
|
stubs: func(t *testing.T, r *httpmock.Registry) {
|
||||||
r.Register(
|
r.Register(
|
||||||
|
|
@ -218,11 +219,12 @@ func Test_repoCreate(t *testing.T) {
|
||||||
}`,
|
}`,
|
||||||
func(inputs map[string]interface{}) {
|
func(inputs map[string]interface{}) {
|
||||||
assert.Equal(t, map[string]interface{}{
|
assert.Equal(t, map[string]interface{}{
|
||||||
"name": "gen-project",
|
"name": "gen-project",
|
||||||
"description": "my generated project",
|
"description": "my generated project",
|
||||||
"visibility": "PRIVATE",
|
"visibility": "PRIVATE",
|
||||||
"ownerId": "USERID",
|
"ownerId": "USERID",
|
||||||
"repositoryId": "TPLID",
|
"repositoryId": "TPLID",
|
||||||
|
"includeAllBranches": false,
|
||||||
}, inputs)
|
}, inputs)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
@ -240,6 +242,7 @@ func Test_repoCreate(t *testing.T) {
|
||||||
TemplateRepositoryID: "TPLID",
|
TemplateRepositoryID: "TPLID",
|
||||||
HasIssuesEnabled: true,
|
HasIssuesEnabled: true,
|
||||||
HasWikiEnabled: true,
|
HasWikiEnabled: true,
|
||||||
|
IncludeAllBranches: false,
|
||||||
},
|
},
|
||||||
stubs: func(t *testing.T, r *httpmock.Registry) {
|
stubs: func(t *testing.T, r *httpmock.Registry) {
|
||||||
r.Register(
|
r.Register(
|
||||||
|
|
@ -262,11 +265,12 @@ func Test_repoCreate(t *testing.T) {
|
||||||
}`,
|
}`,
|
||||||
func(inputs map[string]interface{}) {
|
func(inputs map[string]interface{}) {
|
||||||
assert.Equal(t, map[string]interface{}{
|
assert.Equal(t, map[string]interface{}{
|
||||||
"name": "gen-project",
|
"name": "gen-project",
|
||||||
"description": "my generated project",
|
"description": "my generated project",
|
||||||
"visibility": "INTERNAL",
|
"visibility": "INTERNAL",
|
||||||
"ownerId": "ORGID",
|
"ownerId": "ORGID",
|
||||||
"repositoryId": "TPLID",
|
"repositoryId": "TPLID",
|
||||||
|
"includeAllBranches": false,
|
||||||
}, inputs)
|
}, inputs)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue