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
22 changes: 19 additions & 3 deletions cmd/issue_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/MakeNowJust/heredoc/v2"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/action"
lab "github.com/zaquestion/lab/internal/gitlab"
Expand Down Expand Up @@ -133,9 +134,24 @@ var issueEditCmd = &cobra.Command{
title := issue.Title
body := issue.Description

// We only consider editing an issue with -m or when no other flag is
// passed, but --linebreak.
if len(msgs) > 0 || cmd.Flags().NFlag() == 0 || (cmd.Flags().NFlag() == 1 && linebreak) {
// We only consider opening the editor to edit the title and body on
// -m, when --force-linebreak is used alone, or when no other flag is
// passed. However, it's common to set --force-linebreak through the
// config file, so we need to check if it's being set through the CLI
// or config file.
var openEditor bool
if len(msgs) > 0 || cmd.Flags().NFlag() == 0 {
openEditor = true
} else if linebreak && cmd.Flags().NFlag() == 1 {
cmd.Flags().Visit(func(f *pflag.Flag) {
if f.Name == "force-linebreak" {
openEditor = true
return
}
})
}

if openEditor {
title, body, err = editDescription(issue.Title, issue.Description, msgs, "")
if err != nil {
log.Fatal(err)
Expand Down
23 changes: 19 additions & 4 deletions cmd/mr_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/action"
lab "github.com/zaquestion/lab/internal/gitlab"
Expand Down Expand Up @@ -194,10 +195,24 @@ var mrEditCmd = &cobra.Command{
log.Fatal("option -F cannot be combined with -m")
}

// We only consider editing title and body on -m, -F or when no other
// flag is passed, but --linebreak.
if len(msgs) > 0 || filename != "" ||
cmd.Flags().NFlag() == 0 || (cmd.Flags().NFlag() == 1 && linebreak) {
// We only consider opening the editor to edit the title and body on
// -m, -F, when --force-linebreak is used alone, or when no other flag
// is passed. However, it's common to set --force-linebreak through the
// config file, so we need to check if it's being set through the CLI
// or config file.
var openEditor bool
if len(msgs) > 0 || filename != "" || cmd.Flags().NFlag() == 0 {
openEditor = true
} else if linebreak && cmd.Flags().NFlag() == 1 {
cmd.Flags().Visit(func(f *pflag.Flag) {
if f.Name == "force-linebreak" {
openEditor = true
return
}
})
}

if openEditor {
title, body, err = editDescription(mr.Title, mr.Description, msgs, filename)
if err != nil {
log.Fatal(err)
Expand Down