Add `--remove-milestone` option to `issue edit` and `pr edit` by babakks · Pull Request #9344 · cli/cli · GitHub
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
18 changes: 17 additions & 1 deletion pkg/cmd/issue/edit/edit.go
29 changes: 22 additions & 7 deletions pkg/cmd/issue/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func TestNewCmdEdit(t *testing.T) {
},
wantsErr: false,
},
{
name: "both body and body-file flags",
input: "23 --body foo --body-file bar",
wantsErr: true,
},
{
name: "add-assignee flag",
input: "23 --add-assignee monalisa,hubot",
Expand Down Expand Up @@ -207,22 +212,27 @@ func TestNewCmdEdit(t *testing.T) {
wantsErr: false,
},
{
name: "add label to multiple issues",
input: "23 34 --add-label bug",
name: "remove-milestone flag",
input: "23 --remove-milestone",
output: EditOptions{
SelectorArgs: []string{"23", "34"},
SelectorArgs: []string{"23"},
Editable: prShared.Editable{
Labels: prShared.EditableSlice{
Add: []string{"bug"},
Milestone: prShared.EditableString{
Value: "",
Edited: true,
},
},
},
wantsErr: false,
},
{
name: "interactive multiple issues",
input: "23 34",
name: "both milestone and remove-milestone flags",
input: "23 --milestone foo --remove-milestone",
wantsErr: true,
},
{
name: "add label to multiple issues",
input: "23 34 --add-label bug",
output: EditOptions{
SelectorArgs: []string{"23", "34"},
Editable: prShared.Editable{
Expand All @@ -232,6 +242,11 @@ func TestNewCmdEdit(t *testing.T) {
},
},
},
wantsErr: false,
},
{
name: "interactive multiple issues",
input: "23 34",
wantsErr: true,
},
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/cmd/pr/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
}

var bodyFile string
var removeMilestone bool

cmd := &cobra.Command{
Use: "edit [<number> | <url> | <branch>]",
Expand All @@ -63,6 +64,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
$ gh pr edit 23 --add-assignee "@me" --remove-assignee monalisa,hubot
$ gh pr edit 23 --add-project "Roadmap" --remove-project v1,v2
$ gh pr edit 23 --milestone "Version 1"
$ gh pr edit 23 --remove-milestone
`),
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -95,6 +97,14 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
}
}

if err := cmdutil.MutuallyExclusive(
"specify only one of `--milestone` or `--remove-milestone`",
flags.Changed("milestone"),
removeMilestone,
); err != nil {
return err
}

if flags.Changed("title") {
opts.Editable.Title.Edited = true
}
Expand All @@ -116,8 +126,13 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
if flags.Changed("add-project") || flags.Changed("remove-project") {
opts.Editable.Projects.Edited = true
}
if flags.Changed("milestone") {
if flags.Changed("milestone") || removeMilestone {
opts.Editable.Milestone.Edited = true

// Note that when `--remove-milestone` is provided, the value of
// `opts.Editable.Milestone.Value` will automatically be empty,
// which results in milestone association removal. For reference,
// see the `Editable.MilestoneId` method.
}

if !opts.Editable.Dirty() {
Expand Down Expand Up @@ -149,6 +164,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
cmd.Flags().StringSliceVar(&opts.Editable.Projects.Add, "add-project", nil, "Add the pull request to projects by `name`")
cmd.Flags().StringSliceVar(&opts.Editable.Projects.Remove, "remove-project", nil, "Remove the pull request from projects by `name`")
cmd.Flags().StringVarP(&opts.Editable.Milestone.Value, "milestone", "m", "", "Edit the milestone the pull request belongs to by `name`")
cmd.Flags().BoolVar(&removeMilestone, "remove-milestone", false, "Remove the milestone association from the pull request")

_ = cmdutil.RegisterBranchCompletionFlags(f.GitClient, cmd, "base")

Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/pr/edit/edit_test.go