port more prompts and cover with new tests
This commit is contained in:
parent
8927040028
commit
c1296194ee
2 changed files with 89 additions and 32 deletions
|
|
@ -319,6 +319,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error {
|
|||
}
|
||||
for _, c := range choices {
|
||||
switch c {
|
||||
// TODO these initial assignments are no-ops; delete them
|
||||
case optionDescription:
|
||||
opts.Edits.Description = &r.Description
|
||||
answer, err := opts.Prompter.Input("Description of the repository", r.Description)
|
||||
|
|
@ -328,14 +329,11 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error {
|
|||
opts.Edits.Description = &answer
|
||||
case optionHomePageURL:
|
||||
opts.Edits.Homepage = &r.HomepageURL
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
err = prompt.SurveyAskOne(&survey.Input{
|
||||
Message: "Repository home page URL",
|
||||
Default: r.HomepageURL,
|
||||
}, opts.Edits.Homepage)
|
||||
a, err := opts.Prompter.Input("Repository home page URL", r.HomepageURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Edits.Homepage = &a
|
||||
case optionTopics:
|
||||
addTopics, err := opts.Prompter.Input("Add topics?(csv format)", "")
|
||||
if err != nil {
|
||||
|
|
@ -356,44 +354,32 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error {
|
|||
}
|
||||
case optionDefaultBranchName:
|
||||
opts.Edits.DefaultBranch = &r.DefaultBranchRef.Name
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
err = prompt.SurveyAskOne(&survey.Input{
|
||||
Message: "Default branch name",
|
||||
Default: r.DefaultBranchRef.Name,
|
||||
}, opts.Edits.DefaultBranch)
|
||||
name, err := opts.Prompter.Input("Default branch name", r.DefaultBranchRef.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Edits.DefaultBranch = &name
|
||||
case optionWikis:
|
||||
opts.Edits.EnableWiki = &r.HasWikiEnabled
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
err = prompt.SurveyAskOne(&survey.Confirm{
|
||||
Message: "Enable Wikis?",
|
||||
Default: r.HasWikiEnabled,
|
||||
}, opts.Edits.EnableWiki)
|
||||
c, err := opts.Prompter.Confirm("Enable Wikis?", r.HasWikiEnabled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Edits.EnableWiki = &c
|
||||
case optionIssues:
|
||||
opts.Edits.EnableIssues = &r.HasIssuesEnabled
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
err = prompt.SurveyAskOne(&survey.Confirm{
|
||||
Message: "Enable Issues?",
|
||||
Default: r.HasIssuesEnabled,
|
||||
}, opts.Edits.EnableIssues)
|
||||
a, err := opts.Prompter.Confirm("Enable Issues?", r.HasIssuesEnabled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Edits.EnableIssues = &a
|
||||
case optionProjects:
|
||||
opts.Edits.EnableProjects = &r.HasProjectsEnabled
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
err = prompt.SurveyAskOne(&survey.Confirm{
|
||||
Message: "Enable Projects?",
|
||||
Default: r.HasProjectsEnabled,
|
||||
}, opts.Edits.EnableProjects)
|
||||
a, err := opts.Prompter.Confirm("Enable Projects?", r.HasProjectsEnabled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Edits.EnableProjects = &a
|
||||
case optionVisibility:
|
||||
opts.Edits.Visibility = &r.Visibility
|
||||
visibilityOptions := []string{"public", "private", "internal"}
|
||||
|
|
@ -463,14 +449,11 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error {
|
|||
opts.Edits.DeleteBranchOnMerge = &c
|
||||
case optionTemplateRepo:
|
||||
opts.Edits.IsTemplate = &r.IsTemplate
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
err = prompt.SurveyAskOne(&survey.Confirm{
|
||||
Message: "Convert into a template repository?",
|
||||
Default: r.IsTemplate,
|
||||
}, opts.Edits.IsTemplate)
|
||||
c, err := opts.Prompter.Confirm("Convert into a template repository?", r.IsTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Edits.IsTemplate = &c
|
||||
case optionAllowForking:
|
||||
opts.Edits.AllowForking = &r.ForkingAllowed
|
||||
//nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter
|
||||
|
|
|
|||
|
|
@ -173,8 +173,6 @@ func Test_editRun(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO consider unit test for interactiveRepoEdit that exercises every prompt type
|
||||
|
||||
func Test_editRun_interactive(t *testing.T) {
|
||||
editList := []string{
|
||||
"Default Branch Name",
|
||||
|
|
@ -196,6 +194,82 @@ func Test_editRun_interactive(t *testing.T) {
|
|||
wantsStderr string
|
||||
wantsErr string
|
||||
}{
|
||||
// TODO forking of an org repo
|
||||
{
|
||||
name: "the rest",
|
||||
opts: EditOptions{
|
||||
Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"),
|
||||
InteractiveMode: true,
|
||||
},
|
||||
promptStubs: func(pm *prompter.MockPrompter) {
|
||||
pm.RegisterMultiSelect("What do you want to edit?", nil, editList,
|
||||
func(_ string, _, opts []string) ([]int, error) {
|
||||
return []int{0, 2, 3, 5, 6, 8, 9}, nil
|
||||
})
|
||||
pm.RegisterInput("Default branch name", func(_, _ string) (string, error) {
|
||||
return "trunk", nil
|
||||
})
|
||||
pm.RegisterInput("Repository home page URL", func(_, _ string) (string, error) {
|
||||
return "https://zombo.com", nil
|
||||
})
|
||||
pm.RegisterConfirm("Enable Issues?", func(_ string, _ bool) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
pm.RegisterConfirm("Enable Projects?", func(_ string, _ bool) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
pm.RegisterConfirm("Convert into a template repository?", func(_ string, _ bool) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
pm.RegisterSelect("Visibility", []string{"public", "private", "internal"},
|
||||
func(_, _ string, opts []string) (int, error) {
|
||||
return prompter.IndexFor(opts, "private")
|
||||
})
|
||||
pm.RegisterConfirm("Do you want to change visibility to private?", func(_ string, _ bool) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
pm.RegisterConfirm("Enable Wikis?", func(_ string, _ bool) (bool, error) {
|
||||
return true, nil
|
||||
})
|
||||
},
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query RepositoryInfo\b`),
|
||||
httpmock.StringResponse(`
|
||||
{
|
||||
"data": {
|
||||
"repository": {
|
||||
"visibility": "public",
|
||||
"description": "description",
|
||||
"homePageUrl": "https://url.com",
|
||||
"defaultBranchRef": {
|
||||
"name": "main"
|
||||
},
|
||||
"stargazerCount": 10,
|
||||
"isInOrganization": false,
|
||||
"repositoryTopics": {
|
||||
"nodes": [{
|
||||
"topic": {
|
||||
"name": "x"
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}`))
|
||||
reg.Register(
|
||||
httpmock.REST("PATCH", "repos/OWNER/REPO"),
|
||||
httpmock.RESTPayload(200, `{}`, func(payload map[string]interface{}) {
|
||||
assert.Equal(t, "trunk", payload["default_branch"])
|
||||
assert.Equal(t, "https://zombo.com", payload["homepage"])
|
||||
assert.Equal(t, true, payload["has_issues"])
|
||||
assert.Equal(t, true, payload["has_projects"])
|
||||
assert.Equal(t, "private", payload["visibility"])
|
||||
assert.Equal(t, true, payload["is_template"])
|
||||
assert.Equal(t, true, payload["has_wiki"])
|
||||
}))
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "updates repo description",
|
||||
opts: EditOptions{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue