Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ before:
- make man

builds:
- env:
- ldflags:
- -X github.com/jamesjohnsdev/issues/cmd.Version={{.Version}}
env:
- CGO_ENABLED=0
goos:
- linux
Expand Down
44 changes: 24 additions & 20 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 {
Expand Down
32 changes: 31 additions & 1 deletion cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"}},
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package cmd

var Version = "dev"