diff --git a/pkg/cmd/repo/edit/edit.go b/pkg/cmd/repo/edit/edit.go index fb3d87bea..cb11e2622 100644 --- a/pkg/cmd/repo/edit/edit.go +++ b/pkg/cmd/repo/edit/edit.go @@ -10,7 +10,6 @@ import ( "strings" "time" - "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" fd "github.com/cli/cli/v2/internal/featuredetection" @@ -19,7 +18,6 @@ import ( "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/cli/cli/v2/pkg/set" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" @@ -446,15 +444,13 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } opts.Edits.IsTemplate = &c case optionAllowForking: - opts.Edits.AllowForking = &r.ForkingAllowed - //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter - err = prompt.SurveyAskOne(&survey.Confirm{ - Message: "Allow forking (of an organization repository)?", - Default: r.ForkingAllowed, - }, opts.Edits.AllowForking) + c, err := opts.Prompter.Confirm( + "Allow forking (of an organization repository)?", + r.ForkingAllowed) if err != nil { return err } + opts.Edits.AllowForking = &c } } return nil diff --git a/pkg/cmd/repo/edit/edit_test.go b/pkg/cmd/repo/edit/edit_test.go index 0c6a6d2f6..07f7d4d55 100644 --- a/pkg/cmd/repo/edit/edit_test.go +++ b/pkg/cmd/repo/edit/edit_test.go @@ -194,7 +194,53 @@ func Test_editRun_interactive(t *testing.T) { wantsStderr string wantsErr string }{ - // TODO forking of an org repo + { + name: "forking of org repo", + opts: EditOptions{ + Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), + InteractiveMode: true, + }, + promptStubs: func(pm *prompter.MockPrompter) { + el := append(editList, optionAllowForking) + pm.RegisterMultiSelect("What do you want to edit?", nil, el, + func(_ string, _, opts []string) ([]int, error) { + return []int{10}, nil + }) + pm.RegisterConfirm("Allow forking (of an organization repository)?", 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" + }, + "isInOrganization": true, + "repositoryTopics": { + "nodes": [{ + "topic": { + "name": "x" + } + }] + } + } + } + }`)) + reg.Register( + httpmock.REST("PATCH", "repos/OWNER/REPO"), + httpmock.RESTPayload(200, `{}`, func(payload map[string]interface{}) { + assert.Equal(t, true, payload["allow_forking"]) + })) + }, + }, { name: "the rest", opts: EditOptions{