Allow --disable-wiki flag with --template flag in repo create command (#7886)
This commit is contained in:
parent
6fc6b87484
commit
f8bf602ecd
3 changed files with 92 additions and 2 deletions
|
|
@ -164,8 +164,8 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
|
|||
if cmd.Flags().Changed("enable-wiki") {
|
||||
opts.DisableWiki = !enableWiki
|
||||
}
|
||||
if opts.Template != "" && (opts.Homepage != "" || opts.Team != "" || opts.DisableIssues || opts.DisableWiki) {
|
||||
return cmdutil.FlagErrorf("the `--template` option is not supported with `--homepage`, `--team`, `--disable-issues`, or `--disable-wiki`")
|
||||
if opts.Template != "" && (opts.Homepage != "" || opts.Team != "" || opts.DisableIssues) {
|
||||
return cmdutil.FlagErrorf("the `--template` option is not supported with `--homepage`, `--team`, or `--disable-issues`")
|
||||
}
|
||||
|
||||
if opts.Template == "" && opts.IncludeAllBranches {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,11 @@ type cloneTemplateRepositoryInput struct {
|
|||
IncludeAllBranches bool `json:"includeAllBranches"`
|
||||
}
|
||||
|
||||
type updateRepositoryInput struct {
|
||||
RepositoryID string `json:"repositoryId"`
|
||||
HasWikiEnabled bool `json:"hasWikiEnabled"`
|
||||
}
|
||||
|
||||
// repoCreate creates a new GitHub repository
|
||||
func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*api.Repository, error) {
|
||||
isOrg := false
|
||||
|
|
@ -133,6 +138,27 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if !input.HasWikiEnabled {
|
||||
updateVariables := map[string]interface{}{
|
||||
"input": updateRepositoryInput{
|
||||
RepositoryID: response.CloneTemplateRepository.Repository.ID,
|
||||
HasWikiEnabled: input.HasWikiEnabled,
|
||||
},
|
||||
}
|
||||
|
||||
if err := apiClient.GraphQL(hostname, `
|
||||
mutation UpdateRepository($input: UpdateRepositoryInput!) {
|
||||
updateRepository(input: $input) {
|
||||
repository {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`, updateVariables, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return api.InitRepoHostname(&response.CloneTemplateRepository.Repository, hostname), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,6 +231,70 @@ func Test_repoCreate(t *testing.T) {
|
|||
},
|
||||
wantRepo: "https://github.com/OWNER/REPO",
|
||||
},
|
||||
{
|
||||
name: "create personal repo from template repo, and disable wiki",
|
||||
hostname: "github.com",
|
||||
input: repoCreateInput{
|
||||
Name: "gen-project",
|
||||
Description: "my generated project",
|
||||
Visibility: "private",
|
||||
TemplateRepositoryID: "TPLID",
|
||||
HasIssuesEnabled: true,
|
||||
HasWikiEnabled: false,
|
||||
IncludeAllBranches: false,
|
||||
},
|
||||
stubs: func(t *testing.T, r *httpmock.Registry) {
|
||||
r.Register(
|
||||
httpmock.GraphQL(`query UserCurrent\b`),
|
||||
httpmock.StringResponse(`{"data": {"viewer": {"id":"USERID"} } }`))
|
||||
r.Register(
|
||||
httpmock.GraphQL(`mutation CloneTemplateRepository\b`),
|
||||
httpmock.GraphQLMutation(
|
||||
`{
|
||||
"data": {
|
||||
"cloneTemplateRepository": {
|
||||
"repository": {
|
||||
"id": "REPOID",
|
||||
"name": "REPO",
|
||||
"owner": {"login":"OWNER"},
|
||||
"url": "the://URL"
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
func(inputs map[string]interface{}) {
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"name": "gen-project",
|
||||
"description": "my generated project",
|
||||
"visibility": "PRIVATE",
|
||||
"ownerId": "USERID",
|
||||
"repositoryId": "TPLID",
|
||||
"includeAllBranches": false,
|
||||
}, inputs)
|
||||
}),
|
||||
)
|
||||
r.Register(
|
||||
httpmock.GraphQL(`mutation UpdateRepository\b`),
|
||||
httpmock.GraphQLMutation(
|
||||
`{
|
||||
"data": {
|
||||
"updateRepository": {
|
||||
"repository": {
|
||||
"id": "REPOID"
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
func(inputs map[string]interface{}) {
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"repositoryId": "REPOID",
|
||||
"hasWikiEnabled": false,
|
||||
}, inputs)
|
||||
}),
|
||||
)
|
||||
},
|
||||
wantRepo: "https://github.com/OWNER/REPO",
|
||||
},
|
||||
{
|
||||
name: "create org repo from template repo",
|
||||
hostname: "github.com",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue