Skip to content

Commit

Permalink
issue, mr: Allow editing milestone
Browse files Browse the repository at this point in the history
Right now a milestone can only be assigned when creating the issue/MR.
It's not uncommon to change a milestone later (not least to assign one
to an issue/MR created by someone else), so add a corresponding option
to the mr/issue edit commands.
  • Loading branch information
fmuellner committed Jan 12, 2021
1 parent e068d19 commit fd7fd63
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cmd/issue_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ lab issue edit <id>:<comment_id> # update a comment on MR`,
log.Fatal(err)
}

milestoneName, err := cmd.Flags().GetString("milestone")
if err != nil {
log.Fatal(err)
}
updateMilestone := cmd.Flags().Lookup("milestone").Changed
milestoneID := -1

if milestoneName != "" {
ms, err := lab.MilestoneGet(rn, milestoneName)
if err != nil {
log.Fatal(err)
}
milestoneID = ms.ID
}

// get all of the "message" flags
msgs, err := cmd.Flags().GetStringArray("message")
if err != nil {
Expand All @@ -123,7 +138,7 @@ lab issue edit <id>:<comment_id> # update a comment on MR`,
log.Fatal("aborting: empty issue title")
}

abortUpdate := title == issue.Title && body == issue.Description && !labelsChanged && !assigneesChanged
abortUpdate := title == issue.Title && body == issue.Description && !labelsChanged && !assigneesChanged && !updateMilestone
if abortUpdate {
log.Fatal("aborting: no changes")
}
Expand All @@ -145,6 +160,10 @@ lab issue edit <id>:<comment_id> # update a comment on MR`,
opts.AssigneeIDs = assigneeIDs
}

if updateMilestone {
opts.MilestoneID = &milestoneID
}

issueURL, err := lab.IssueUpdate(rn, issueNum, opts)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -315,6 +334,7 @@ func init() {
issueEditCmd.Flags().StringSliceP("unlabel", "", []string{}, "remove the given label(s) from the issue")
issueEditCmd.Flags().StringSliceP("assign", "a", []string{}, "add an assignee by username")
issueEditCmd.Flags().StringSliceP("unassign", "", []string{}, "remove an assignee by username")
issueEditCmd.Flags().String("milestone", "", "set milestone")
issueEditCmd.Flags().Bool("force-linebreak", false, "append 2 spaces to the end of each line to force markdown linebreaks")
issueEditCmd.Flags().SortFlags = false

Expand Down
22 changes: 21 additions & 1 deletion cmd/mr_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ lab MR edit <id>:<comment_id> # update a comment on MR`,
log.Fatal(err)
}

milestoneName, err := cmd.Flags().GetString("milestone")
if err != nil {
log.Fatal(err)
}
updateMilestone := cmd.Flags().Lookup("milestone").Changed
milestoneID := -1

if milestoneName != "" {
ms, err := lab.MilestoneGet(rn, milestoneName)
if err != nil {
log.Fatal(err)
}
milestoneID = ms.ID
}

// get all of the "message" flags
msgs, err := cmd.Flags().GetStringSlice("message")
if err != nil {
Expand Down Expand Up @@ -155,7 +170,7 @@ lab MR edit <id>:<comment_id> # update a comment on MR`,
}
}

abortUpdate := title == mr.Title && body == mr.Description && !labelsChanged && !assigneesChanged
abortUpdate := title == mr.Title && body == mr.Description && !labelsChanged && !assigneesChanged && !updateMilestone
if abortUpdate {
log.Fatal("aborting: no changes")
}
Expand All @@ -177,6 +192,10 @@ lab MR edit <id>:<comment_id> # update a comment on MR`,
opts.AssigneeIDs = assigneeIDs
}

if updateMilestone {
opts.MilestoneID = &milestoneID
}

mrURL, err := lab.MRUpdate(rn, int(mrNum), opts)
if err != nil {
log.Fatal(err)
Expand All @@ -203,6 +222,7 @@ func init() {
mrEditCmd.Flags().StringSliceP("unlabel", "", []string{}, "remove the given label(s) from the merge request")
mrEditCmd.Flags().StringSliceP("assign", "a", []string{}, "add an assignee by username")
mrEditCmd.Flags().StringSliceP("unassign", "", []string{}, "remove an assignee by username")
mrEditCmd.Flags().String("milestone", "", "set milestone")
mrEditCmd.Flags().Bool("force-linebreak", false, "append 2 spaces to the end of each line to force markdown linebreaks")
mrEditCmd.Flags().Bool("draft", false, "mark the merge request as draft")
mrEditCmd.Flags().Bool("ready", false, "mark the merge request as ready")
Expand Down

0 comments on commit fd7fd63

Please sign in to comment.