From 71df609001c277d2f5a44675c4bcb6f4e63e4be8 Mon Sep 17 00:00:00 2001 From: Bruno Meneguele Date: Fri, 11 Jun 2021 15:34:10 -0300 Subject: [PATCH] edit: fix labels update for issue and MR Since the label/unlabel code was written the go-gitlab module was updated and received got the ability to add and remove labels explicitly instead of the specifying all labels through a single struct member. With that, we can use these new members in the UpdateLabel struct to get the job done and solve the issue where it's not possible to unlabel an issue or MR with a single label, since the array would be ignore for being "empty". Signed-off-by: Bruno Meneguele --- cmd/issue_edit.go | 22 +++++++++++++--------- cmd/mr_edit.go | 22 +++++++++++++--------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/cmd/issue_edit.go b/cmd/issue_edit.go index 27cfef90..f79804c4 100644 --- a/cmd/issue_edit.go +++ b/cmd/issue_edit.go @@ -65,29 +65,31 @@ lab issue edit : # update a comment on MR`, return } + var labelsChanged bool // get the labels to add - labelTerms, err := cmd.Flags().GetStringSlice("label") + addLabelTerms, err := cmd.Flags().GetStringSlice("label") if err != nil { log.Fatal(err) } - labels, err := MapLabels(rn, labelTerms) + addLabels, err := MapLabels(rn, addLabelTerms) if err != nil { log.Fatal(err) } + if len(addLabels) > 0 { + labelsChanged = true + } // get the labels to remove - unlabelTerms, err := cmd.Flags().GetStringSlice("unlabel") + rmLabelTerms, err := cmd.Flags().GetStringSlice("unlabel") if err != nil { log.Fatal(err) } - unlabels, err := MapLabels(rn, unlabelTerms) + rmLabels, err := MapLabels(rn, rmLabelTerms) if err != nil { log.Fatal(err) } - - labels, labelsChanged, err := editGetLabels(issue.Labels, labels, unlabels) - if err != nil { - log.Fatal(err) + if len(rmLabels) > 0 { + labelsChanged = true } // get the assignees to add @@ -152,7 +154,9 @@ lab issue edit : # update a comment on MR`, } if labelsChanged { - opts.Labels = labels + // empty arrays are just ignored + opts.AddLabels = addLabels + opts.RemoveLabels = rmLabels } if assigneesChanged { diff --git a/cmd/mr_edit.go b/cmd/mr_edit.go index 3b6e3e9f..1b32322f 100644 --- a/cmd/mr_edit.go +++ b/cmd/mr_edit.go @@ -61,29 +61,31 @@ lab MR edit : # update a comment on MR`, return } + var labelsChanged bool // get the labels to add - labelTerms, err := cmd.Flags().GetStringSlice("label") + addLabelTerms, err := cmd.Flags().GetStringSlice("label") if err != nil { log.Fatal(err) } - labels, err := MapLabels(rn, labelTerms) + addLabels, err := MapLabels(rn, addLabelTerms) if err != nil { log.Fatal(err) } + if len(addLabels) > 0 { + labelsChanged = true + } // get the labels to remove - unlabelTerms, err := cmd.Flags().GetStringSlice("unlabel") + rmLabelTerms, err := cmd.Flags().GetStringSlice("unlabel") if err != nil { log.Fatal(err) } - unlabels, err := MapLabels(rn, unlabelTerms) + rmLabels, err := MapLabels(rn, rmLabelTerms) if err != nil { log.Fatal(err) } - - labels, labelsChanged, err := editGetLabels(mr.Labels, labels, unlabels) - if err != nil { - log.Fatal(err) + if len(rmLabels) > 0 { + labelsChanged = true } // get the assignees to add @@ -243,7 +245,9 @@ lab MR edit : # update a comment on MR`, } if labelsChanged { - opts.Labels = labels + // empty arrays are just ignored + opts.AddLabels = addLabels + opts.RemoveLabels = rmLabels } if assigneesChanged {