Fix respecting chosen action in interactive issue create

The `action` variable started being shadowed in the `if` block in
6671106448
This commit is contained in:
Mislav Marohnić 2020-12-01 15:28:39 +01:00
parent 7c6574d8e9
commit dc1fad9cb0
2 changed files with 57 additions and 1 deletions

View file

@ -199,7 +199,6 @@ func createRun(opts *CreateOptions) (err error) {
}
}
var action prShared.Action
action, err = prShared.ConfirmSubmission(!tb.HasMetadata(), repo.ViewerCanTriage())
if err != nil {
err = fmt.Errorf("unable to confirm: %w", err)

View file

@ -12,6 +12,7 @@ import (
"strings"
"testing"
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/internal/run"
@ -274,6 +275,62 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
eq(t, output.String(), "https://github.com/OWNER/REPO/issues/12\n")
}
func TestIssueCreate_continueInBrowser(t *testing.T) {
http := &httpmock.Registry{}
defer http.Verify(t)
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": {
"id": "REPOID",
"hasIssuesEnabled": true
} } }
`))
as, teardown := prompt.InitAskStubber()
defer teardown()
// title
as.Stub([]*prompt.QuestionStub{
{
Name: "Title",
Value: "hello",
},
})
// confirm
as.Stub([]*prompt.QuestionStub{
{
Name: "confirmation",
Value: 1,
},
})
var seenCmd *exec.Cmd
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := runCommand(http, true, `-b body`)
if err != nil {
t.Errorf("error running command `issue create`: %v", err)
}
assert.Equal(t, "", output.String())
assert.Equal(t, heredoc.Doc(`
Creating issue in OWNER/REPO
Opening github.com/OWNER/REPO/issues/new in your browser.
`), output.Stderr())
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
assert.Equal(t, "https://github.com/OWNER/REPO/issues/new?body=body&title=hello", url)
}
func TestIssueCreate_metadata(t *testing.T) {
http := &httpmock.Registry{}
defer http.Verify(t)