diff --git a/.goreleaser.yaml b/.goreleaser.yaml index dc4a3c4..3242d76 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,7 +5,9 @@ before: - make man builds: - - env: + - ldflags: + - -X github.com/jamesjohnsdev/issues/cmd.Version={{.Version}} + env: - CGO_ENABLED=0 goos: - linux diff --git a/cmd/create.go b/cmd/create.go index b9ed4e9..385d394 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -104,29 +104,31 @@ var createCmd = &cobra.Command{ openEditor = false } - labelsResp, err := prompt("Labels (comma-separated, Enter to skip): ") - if err != nil { - return err - } - for _, l := range strings.Split(labelsResp, ",") { - if l := strings.TrimSpace(l); l != "" { - iss.Labels = append(iss.Labels, l) + if !openEditor { + labelsResp, err := prompt("Labels (comma-separated, Enter to skip): ") + if err != nil { + return err + } + for _, l := range strings.Split(labelsResp, ",") { + if l := strings.TrimSpace(l); l != "" { + iss.Labels = append(iss.Labels, l) + } } - } - assigneesResp, err := prompt("Assignees (comma-separated, Enter to skip): ") - if err != nil { - return err - } - for _, a := range strings.Split(assigneesResp, ",") { - if a := strings.TrimSpace(a); a != "" { - iss.Assignees = append(iss.Assignees, a) + assigneesResp, err := prompt("Assignees (comma-separated, Enter to skip): ") + if err != nil { + return err + } + for _, a := range strings.Split(assigneesResp, ",") { + if a := strings.TrimSpace(a); a != "" { + iss.Assignees = append(iss.Assignees, a) + } } - } - iss.Milestone, err = prompt("Milestone (Enter to skip): ") - if err != nil { - return err + iss.Milestone, err = prompt("Milestone (Enter to skip): ") + if err != nil { + return err + } } default: @@ -153,7 +155,9 @@ var createCmd = &cobra.Command{ c.Stdin = os.Stdin c.Stdout = os.Stdout c.Stderr = os.Stderr - _ = c.Run() + if err := c.Run(); err != nil { + return fmt.Errorf("editor exited with error: %w", err) + } } if createEditorFlag { diff --git a/cmd/create_test.go b/cmd/create_test.go index 2303490..537c5f0 100644 --- a/cmd/create_test.go +++ b/cmd/create_test.go @@ -255,7 +255,8 @@ func TestCreateInteractive(t *testing.T) { t.Setenv("VISUAL", "") t.Setenv("EDITOR", script) - injectStdin(t, "My Bug\ne\n\n\n\n") + // Only title + body "e" — no labels/assignees/milestone prompts should appear. + injectStdin(t, "My Bug\ne\n") _ = captureStdout(t, func() { if err := createCmd.RunE(createCmd, nil); err != nil { t.Fatalf("unexpected error: %v", err) @@ -275,6 +276,35 @@ func TestCreateInteractive(t *testing.T) { } }) + t.Run("body e with editor skips labels assignees milestone prompts", func(t *testing.T) { + parent := makeProjectDir(t, nil) + chdirTo(t, parent) + resetCreateFlag(t) + + script := filepath.Join(t.TempDir(), "editor.sh") + if err := os.WriteFile(script, []byte( + "#!/bin/sh\ncat > \"$1\" <<'EOF'\n---\ntitle: My Bug\nstate: open\n---\nEOF\n", + ), 0755); err != nil { + t.Fatal(err) + } + t.Setenv("VISUAL", "") + t.Setenv("EDITOR", script) + + // If Labels/Assignees/Milestone prompts were shown, this input would + // block waiting for three more lines. Completing without hanging + // confirms they are skipped. + injectStdin(t, "My Bug\ne\n") + _ = captureStdout(t, func() { + if err := createCmd.RunE(createCmd, nil); err != nil { + t.Fatalf("unexpected error: %v", err) + } + }) + + if files := readMDFiles(t, openIssuesDir(t, parent)); len(files) != 1 { + t.Errorf("expected 1 file, got %d", len(files)) + } + }) + t.Run("T-number increments from existing issues", func(t *testing.T) { parent := makeProjectDir(t, []issueFixture{ {"T1-existing.md", issue.Issue{Title: "Existing", State: "open"}}, diff --git a/cmd/root.go b/cmd/root.go index 0929d18..737922f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,8 +9,9 @@ import ( ) var rootCmd = &cobra.Command{ - Use: "issues", - Short: "Local GitHub issue management", + Use: "issues", + Short: "Local GitHub issue management", + Version: Version, } func Execute() { diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..cee8645 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,3 @@ +package cmd + +var Version = "dev"