X Tutup
Skip to content

Commit dc1fad9

Browse files
committed
Fix respecting chosen action in interactive issue create
The `action` variable started being shadowed in the `if` block in 6671106
1 parent 7c6574d commit dc1fad9

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pkg/cmd/issue/create/create.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ func createRun(opts *CreateOptions) (err error) {
199199
}
200200
}
201201

202-
var action prShared.Action
203202
action, err = prShared.ConfirmSubmission(!tb.HasMetadata(), repo.ViewerCanTriage())
204203
if err != nil {
205204
err = fmt.Errorf("unable to confirm: %w", err)

pkg/cmd/issue/create/create_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15+
"github.com/MakeNowJust/heredoc"
1516
"github.com/cli/cli/internal/config"
1617
"github.com/cli/cli/internal/ghrepo"
1718
"github.com/cli/cli/internal/run"
@@ -274,6 +275,62 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
274275
eq(t, output.String(), "https://github.com/OWNER/REPO/issues/12\n")
275276
}
276277

278+
func TestIssueCreate_continueInBrowser(t *testing.T) {
279+
http := &httpmock.Registry{}
280+
defer http.Verify(t)
281+
282+
http.StubResponse(200, bytes.NewBufferString(`
283+
{ "data": { "repository": {
284+
"id": "REPOID",
285+
"hasIssuesEnabled": true
286+
} } }
287+
`))
288+
289+
as, teardown := prompt.InitAskStubber()
290+
defer teardown()
291+
292+
// title
293+
as.Stub([]*prompt.QuestionStub{
294+
{
295+
Name: "Title",
296+
Value: "hello",
297+
},
298+
})
299+
// confirm
300+
as.Stub([]*prompt.QuestionStub{
301+
{
302+
Name: "confirmation",
303+
Value: 1,
304+
},
305+
})
306+
307+
var seenCmd *exec.Cmd
308+
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
309+
seenCmd = cmd
310+
return &test.OutputStub{}
311+
})
312+
defer restoreCmd()
313+
314+
output, err := runCommand(http, true, `-b body`)
315+
if err != nil {
316+
t.Errorf("error running command `issue create`: %v", err)
317+
}
318+
319+
assert.Equal(t, "", output.String())
320+
assert.Equal(t, heredoc.Doc(`
321+
322+
Creating issue in OWNER/REPO
323+
324+
Opening github.com/OWNER/REPO/issues/new in your browser.
325+
`), output.Stderr())
326+
327+
if seenCmd == nil {
328+
t.Fatal("expected a command to run")
329+
}
330+
url := seenCmd.Args[len(seenCmd.Args)-1]
331+
assert.Equal(t, "https://github.com/OWNER/REPO/issues/new?body=body&title=hello", url)
332+
}
333+
277334
func TestIssueCreate_metadata(t *testing.T) {
278335
http := &httpmock.Registry{}
279336
defer http.Verify(t)

0 commit comments

Comments
 (0)
X Tutup