Skip to content

Commit b85c97f

Browse files
committed
fix: editor opens when passing through e
- fixes #32 - failure due to continuation of subsequent steps rather than early exit - test suite updated
1 parent b3fcdcf commit b85c97f

2 files changed

Lines changed: 55 additions & 21 deletions

File tree

cmd/create.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,31 @@ var createCmd = &cobra.Command{
104104
openEditor = false
105105
}
106106

107-
labelsResp, err := prompt("Labels (comma-separated, Enter to skip): ")
108-
if err != nil {
109-
return err
110-
}
111-
for _, l := range strings.Split(labelsResp, ",") {
112-
if l := strings.TrimSpace(l); l != "" {
113-
iss.Labels = append(iss.Labels, l)
107+
if !openEditor {
108+
labelsResp, err := prompt("Labels (comma-separated, Enter to skip): ")
109+
if err != nil {
110+
return err
111+
}
112+
for _, l := range strings.Split(labelsResp, ",") {
113+
if l := strings.TrimSpace(l); l != "" {
114+
iss.Labels = append(iss.Labels, l)
115+
}
114116
}
115-
}
116117

117-
assigneesResp, err := prompt("Assignees (comma-separated, Enter to skip): ")
118-
if err != nil {
119-
return err
120-
}
121-
for _, a := range strings.Split(assigneesResp, ",") {
122-
if a := strings.TrimSpace(a); a != "" {
123-
iss.Assignees = append(iss.Assignees, a)
118+
assigneesResp, err := prompt("Assignees (comma-separated, Enter to skip): ")
119+
if err != nil {
120+
return err
121+
}
122+
for _, a := range strings.Split(assigneesResp, ",") {
123+
if a := strings.TrimSpace(a); a != "" {
124+
iss.Assignees = append(iss.Assignees, a)
125+
}
124126
}
125-
}
126127

127-
iss.Milestone, err = prompt("Milestone (Enter to skip): ")
128-
if err != nil {
129-
return err
128+
iss.Milestone, err = prompt("Milestone (Enter to skip): ")
129+
if err != nil {
130+
return err
131+
}
130132
}
131133

132134
default:
@@ -153,7 +155,9 @@ var createCmd = &cobra.Command{
153155
c.Stdin = os.Stdin
154156
c.Stdout = os.Stdout
155157
c.Stderr = os.Stderr
156-
_ = c.Run()
158+
if err := c.Run(); err != nil {
159+
return fmt.Errorf("editor exited with error: %w", err)
160+
}
157161
}
158162

159163
if createEditorFlag {

cmd/create_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ func TestCreateInteractive(t *testing.T) {
255255
t.Setenv("VISUAL", "")
256256
t.Setenv("EDITOR", script)
257257

258-
injectStdin(t, "My Bug\ne\n\n\n\n")
258+
// Only title + body "e" — no labels/assignees/milestone prompts should appear.
259+
injectStdin(t, "My Bug\ne\n")
259260
_ = captureStdout(t, func() {
260261
if err := createCmd.RunE(createCmd, nil); err != nil {
261262
t.Fatalf("unexpected error: %v", err)
@@ -275,6 +276,35 @@ func TestCreateInteractive(t *testing.T) {
275276
}
276277
})
277278

279+
t.Run("body e with editor skips labels assignees milestone prompts", func(t *testing.T) {
280+
parent := makeProjectDir(t, nil)
281+
chdirTo(t, parent)
282+
resetCreateFlag(t)
283+
284+
script := filepath.Join(t.TempDir(), "editor.sh")
285+
if err := os.WriteFile(script, []byte(
286+
"#!/bin/sh\ncat > \"$1\" <<'EOF'\n---\ntitle: My Bug\nstate: open\n---\nEOF\n",
287+
), 0755); err != nil {
288+
t.Fatal(err)
289+
}
290+
t.Setenv("VISUAL", "")
291+
t.Setenv("EDITOR", script)
292+
293+
// If Labels/Assignees/Milestone prompts were shown, this input would
294+
// block waiting for three more lines. Completing without hanging
295+
// confirms they are skipped.
296+
injectStdin(t, "My Bug\ne\n")
297+
_ = captureStdout(t, func() {
298+
if err := createCmd.RunE(createCmd, nil); err != nil {
299+
t.Fatalf("unexpected error: %v", err)
300+
}
301+
})
302+
303+
if files := readMDFiles(t, openIssuesDir(t, parent)); len(files) != 1 {
304+
t.Errorf("expected 1 file, got %d", len(files))
305+
}
306+
})
307+
278308
t.Run("T-number increments from existing issues", func(t *testing.T) {
279309
parent := makeProjectDir(t, []issueFixture{
280310
{"T1-existing.md", issue.Issue{Title: "Existing", State: "open"}},

0 commit comments

Comments
 (0)