update(repo create): Support for --homepage flag for template-based repository creation flow (#8188)
This commit is contained in:
parent
bc0f63b043
commit
9b037ffac1
3 changed files with 139 additions and 5 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 != "") {
|
||||
return cmdutil.FlagErrorf("the `--template` option is not supported with `--homepage`, or `--team`")
|
||||
if opts.Template != "" && opts.Team != "" {
|
||||
return cmdutil.FlagErrorf("the `--template` option is not supported with `--team`")
|
||||
}
|
||||
|
||||
if opts.Template == "" && opts.IncludeAllBranches {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ type updateRepositoryInput struct {
|
|||
RepositoryID string `json:"repositoryId"`
|
||||
HasWikiEnabled bool `json:"hasWikiEnabled"`
|
||||
HasIssuesEnabled bool `json:"hasIssuesEnabled"`
|
||||
HomepageURL string `json:"homepageUrl,omitempty"`
|
||||
}
|
||||
|
||||
// repoCreate creates a new GitHub repository
|
||||
|
|
@ -140,12 +141,13 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if !input.HasWikiEnabled || !input.HasIssuesEnabled {
|
||||
if !input.HasWikiEnabled || !input.HasIssuesEnabled || input.HomepageURL != "" {
|
||||
updateVariables := map[string]interface{}{
|
||||
"input": updateRepositoryInput{
|
||||
RepositoryID: response.CloneTemplateRepository.Repository.ID,
|
||||
HasWikiEnabled: input.HasWikiEnabled,
|
||||
HasIssuesEnabled: input.HasIssuesEnabled,
|
||||
HomepageURL: input.HomepageURL,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -288,8 +288,8 @@ func Test_repoCreate(t *testing.T) {
|
|||
func(inputs map[string]interface{}) {
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"repositoryId": "REPOID",
|
||||
"hasWikiEnabled": false,
|
||||
"hasIssuesEnabled": true,
|
||||
"hasWikiEnabled": false,
|
||||
}, inputs)
|
||||
}),
|
||||
)
|
||||
|
|
@ -353,8 +353,140 @@ func Test_repoCreate(t *testing.T) {
|
|||
func(inputs map[string]interface{}) {
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"repositoryId": "REPOID",
|
||||
"hasWikiEnabled": true,
|
||||
"hasIssuesEnabled": false,
|
||||
"hasWikiEnabled": true,
|
||||
}, inputs)
|
||||
}),
|
||||
)
|
||||
},
|
||||
wantRepo: "https://github.com/OWNER/REPO",
|
||||
},
|
||||
{
|
||||
name: "create personal repo from template repo, and disable both wiki and issues",
|
||||
hostname: "github.com",
|
||||
input: repoCreateInput{
|
||||
Name: "gen-project",
|
||||
Description: "my generated project",
|
||||
Visibility: "private",
|
||||
TemplateRepositoryID: "TPLID",
|
||||
HasIssuesEnabled: false,
|
||||
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",
|
||||
"hasIssuesEnabled": false,
|
||||
"hasWikiEnabled": false,
|
||||
}, inputs)
|
||||
}),
|
||||
)
|
||||
},
|
||||
wantRepo: "https://github.com/OWNER/REPO",
|
||||
},
|
||||
{
|
||||
name: "create personal repo from template repo, and set homepage url",
|
||||
hostname: "github.com",
|
||||
input: repoCreateInput{
|
||||
Name: "gen-project",
|
||||
Description: "my generated project",
|
||||
Visibility: "private",
|
||||
TemplateRepositoryID: "TPLID",
|
||||
HasIssuesEnabled: true,
|
||||
HasWikiEnabled: true,
|
||||
IncludeAllBranches: false,
|
||||
HomepageURL: "https://example.com",
|
||||
},
|
||||
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",
|
||||
"hasIssuesEnabled": true,
|
||||
"hasWikiEnabled": true,
|
||||
"homepageUrl": "https://example.com",
|
||||
}, inputs)
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue