From 83e0aa7250303a94d0361f6fc52c48237fea9bcd Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:00:30 +0200 Subject: [PATCH 1/7] chore(mod): Update go-gitlab to the newest version --- go.mod | 10 +++++----- go.sum | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index fc00f9c1b..1bd3fd2ec 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 github.com/tidwall/pretty v1.2.0 - github.com/xanzy/go-gitlab v0.51.1 + github.com/xanzy/go-gitlab v0.59.0 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b @@ -67,11 +67,11 @@ require ( github.com/sergi/go-diff v1.0.0 // indirect github.com/yuin/goldmark v1.4.2 // indirect github.com/yuin/goldmark-emoji v1.0.1 // indirect - golang.org/x/net v0.0.0-20211101193420-4a448f8816b3 // indirect - golang.org/x/oauth2 v0.0.0-20211028175245-ba495a64dcb5 // indirect - golang.org/x/sys v0.0.0-20211103184734-ae416a5f93c7 // indirect + golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect + golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect + golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect + golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 53aa8af09..9d6eafa1a 100644 --- a/go.sum +++ b/go.sum @@ -354,6 +354,8 @@ github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/xanzy/go-gitlab v0.51.1 h1:wWKLalwx4omxFoHh3PLs9zDgAD4GXDP/uoxwMRCSiWM= github.com/xanzy/go-gitlab v0.51.1/go.mod h1:Q+hQhV508bDPoBijv7YjK/Lvlb4PhVhJdKqXVQrUoAE= +github.com/xanzy/go-gitlab v0.59.0 h1:fAr6rT/YIdfmBavYgI42+Op7yAAex2Y4xOfvbjN9hxQ= +github.com/xanzy/go-gitlab v0.59.0/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -460,6 +462,9 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211101193420-4a448f8816b3 h1:VrJZAjbekhoRn7n5FBujY31gboH+iB3pdLxn3gE9FjU= golang.org/x/net v0.0.0-20211101193420-4a448f8816b3/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -475,6 +480,8 @@ golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211028175245-ba495a64dcb5 h1:v79phzBz03tsVCUTbvTBmmC3CUXF5mKYt7DA4ZVldpM= golang.org/x/oauth2 v0.0.0-20211028175245-ba495a64dcb5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM= +golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -538,6 +545,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211103184734-ae416a5f93c7 h1:wQUOddybiV2Rfc8FX691KCOx5yEoZlfwpBjtKV6huYo= golang.org/x/sys v0.0.0-20211103184734-ae416a5f93c7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -559,6 +568,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 h1:M73Iuj3xbbb9Uk1DYhzydthsj6oOd6l9bpuFcNoUvTs= +golang.org/x/time v0.0.0-20220224211638-0e9765cccd65/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= From 5d7872bfb0f869ba5279c50f77f9af44a90be276 Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:01:28 +0200 Subject: [PATCH 2/7] fix(api): Change from using retry request to option variable The remove variable API didn't have option to set the enviorment scope, so there was an workaround by hooking into the request retry option, and setting the scope option by hand there. This was fixed in the latest release of go-gitlab and now this can be done simply by passing in a option object. --- api/variable.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/api/variable.go b/api/variable.go index 8edbbc23c..37c8944e0 100644 --- a/api/variable.go +++ b/api/variable.go @@ -35,16 +35,12 @@ var DeleteProjectVariable = func(client *gitlab.Client, projectID interface{}, k client = apiClient.Lab() } - var filter = func(request *retryablehttp.Request) error { - q := request.URL.Query() - q.Add("filter[environment_scope]", scope) - - request.URL.RawQuery = q.Encode() - - return nil + opts := gitlab.RemoveProjectVariableOptions{} + if scope != "" { + opts.Filter = &gitlab.VariableFilter{EnvironmentScope: scope} } - _, err := client.ProjectVariables.RemoveVariable(projectID, key, filter) + _, err := client.ProjectVariables.RemoveVariable(projectID, key, &opts) if err != nil { return err From 03213f6ad57b6205ac4dd3caea091d8802d42504 Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:05:05 +0200 Subject: [PATCH 3/7] fix(release): Pass IO reader form upload command The upload command now takes a io.Reader and a file name. This is why we need to pass it by hand now --- commands/release/releaseutils/upload/upload.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/commands/release/releaseutils/upload/upload.go b/commands/release/releaseutils/upload/upload.go index 8d17e4ba7..868c11851 100644 --- a/commands/release/releaseutils/upload/upload.go +++ b/commands/release/releaseutils/upload/upload.go @@ -55,8 +55,14 @@ func (c *Context) UploadFiles(projectID, tagName string) error { color.ProgressIcon(), color.Blue("file"), file.Path, color.Blue("name"), file.Name) + readCloser, err := file.Open() + if err != nil { + return err + } + projectFile, _, err := c.Client.Projects.UploadFile( projectID, + readCloser, file.Path, nil, ) From cf104ffbbb6df61b4901097312683bd945201468 Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:08:17 +0200 Subject: [PATCH 4/7] fix(api): Pass pass pointer to slice for listing milestones This has been a change around the whole go-gitlab API --- api/milestone.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/milestone.go b/api/milestone.go index 9fab2c391..0392a75e6 100644 --- a/api/milestone.go +++ b/api/milestone.go @@ -45,7 +45,7 @@ type ListMilestonesOptions struct { func (opts *ListMilestonesOptions) ListProjectMilestonesOptions() *gitlab.ListMilestonesOptions { projectOpts := &gitlab.ListMilestonesOptions{ - IIDs: opts.IIDs, + IIDs: &opts.IIDs, State: opts.State, Title: opts.Title, Search: opts.Search, @@ -57,7 +57,7 @@ func (opts *ListMilestonesOptions) ListProjectMilestonesOptions() *gitlab.ListMi func (opts *ListMilestonesOptions) ListGroupMilestonesOptions() *gitlab.ListGroupMilestonesOptions { groupOpts := &gitlab.ListGroupMilestonesOptions{ - IIDs: opts.IIDs, + IIDs: &opts.IIDs, State: opts.State, Title: opts.Title, Search: opts.Search, From db2fc9521adabc025f5beeca24fe06f74dde3c2f Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:09:04 +0200 Subject: [PATCH 5/7] fix(api): Use correct Assigne/Reviewer types These variables are not their own specific types --- api/merge_request.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/merge_request.go b/api/merge_request.go index d711aa367..41e4fdf7c 100644 --- a/api/merge_request.go +++ b/api/merge_request.go @@ -111,7 +111,7 @@ var ListMRsWithAssigneesOrReviewers = func(client *gitlab.Client, projectID inte mrs := make([]*gitlab.MergeRequest, 0) for _, id := range assigneeIds { - opts.AssigneeID = gitlab.Int(id) + opts.AssigneeID = gitlab.AssigneeID(id) assingeMrs, err := ListMRs(client, projectID, opts) if err != nil { return nil, err @@ -120,7 +120,7 @@ var ListMRsWithAssigneesOrReviewers = func(client *gitlab.Client, projectID inte } opts.AssigneeID = nil // reset because it's Assignee OR Reviewer for _, id := range reviewerIds { - opts.ReviewerID = gitlab.Int(id) + opts.ReviewerID = gitlab.ReviewerID(id) reviewerMrs, err := ListMRs(client, projectID, opts) if err != nil { return nil, err From 365c71e17274568ab6f8e6962af7efe6e8ee16a6 Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:14:27 +0200 Subject: [PATCH 6/7] fix(commands): Type fixes for different GitLab API opts --- commands/ci/run/run.go | 2 +- commands/cmdutils/cmdutils.go | 10 +++++----- commands/issue/board/view/issue_board_view.go | 2 +- commands/issue/create/issue_create.go | 2 +- commands/issue/list/issue_list.go | 4 ++-- commands/issue/update/issue_update.go | 6 +++--- commands/mr/create/mr_create.go | 4 ++-- commands/mr/for/mr_for.go | 6 +++--- commands/mr/list/mr_list.go | 2 +- commands/mr/update/mr_update.go | 6 +++--- commands/release/create/create.go | 4 ++-- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/commands/ci/run/run.go b/commands/ci/run/run.go index 2e3860ecd..d2806cfa0 100644 --- a/commands/ci/run/run.go +++ b/commands/ci/run/run.go @@ -82,7 +82,7 @@ func NewCmdRun(f *cmdutils.Factory) *cobra.Command { } c := &gitlab.CreatePipelineOptions{ - Variables: pipelineVars, + Variables: &pipelineVars, } if m, _ := cmd.Flags().GetString("branch"); m != "" { diff --git a/commands/cmdutils/cmdutils.go b/commands/cmdutils/cmdutils.go index b819c5ee3..637722754 100644 --- a/commands/cmdutils/cmdutils.go +++ b/commands/cmdutils/cmdutils.go @@ -352,12 +352,12 @@ func PickMetadata() ([]Action, error) { } //IDsFromUsers collects all user IDs from a slice of users -func IDsFromUsers(users []*gitlab.User) []int { +func IDsFromUsers(users []*gitlab.User) *[]int { ids := make([]int, len(users)) for i, user := range users { ids[i] = user.ID } - return ids + return &ids } func ParseMilestone(apiClient *gitlab.Client, repo glrepo.Interface, milestoneTitle string) (int, error) { @@ -433,7 +433,7 @@ func (ua *UserAssignments) VerifyAssignees() error { // UsersFromReplaces converts all users from the `ToReplace` member of the struct into // an Slice of String representing the Users' IDs, it also takes a Slice of Strings and // writes a proper action message to it -func (ua *UserAssignments) UsersFromReplaces(apiClient *gitlab.Client, actions []string) ([]int, []string, error) { +func (ua *UserAssignments) UsersFromReplaces(apiClient *gitlab.Client, actions []string) (*[]int, []string, error) { users, err := api.UsersByNames(apiClient, ua.ToReplace) if err != nil { return nil, actions, err @@ -463,7 +463,7 @@ func (ua *UserAssignments) UsersFromAddRemove( mergeRequestAssignees []*gitlab.BasicUser, apiClient *gitlab.Client, actions []string, -) ([]int, []string, error) { +) (*[]int, []string, error) { var assignedIDs []int var usernames []string @@ -533,7 +533,7 @@ func (ua *UserAssignments) UsersFromAddRemove( if len(assignedIDs) == 0 { assignedIDs = []int{0} } - return assignedIDs, actions, nil + return &assignedIDs, actions, nil } func ConfirmTransfer() error { diff --git a/commands/issue/board/view/issue_board_view.go b/commands/issue/board/view/issue_board_view.go index cbb8d85f7..34037d8d4 100644 --- a/commands/issue/board/view/issue_board_view.go +++ b/commands/issue/board/view/issue_board_view.go @@ -82,7 +82,7 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command { var boardIssues string issues, err = api.ListIssues(apiClient, repo.FullName(), &gitlab.ListProjectIssuesOptions{ State: gitlab.String("opened"), - Labels: gitlab.Labels{list.Label.Name}, + Labels: &gitlab.Labels{list.Label.Name}, }) if err != nil { return fmt.Errorf("error retrieving list issues: %w", err) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index f2443cd9f..b6c578fa7 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -316,7 +316,7 @@ func createRun(opts *CreateOpts) error { if action == cmdutils.SubmitAction { issueCreateOpts.Title = gitlab.String(opts.Title) - issueCreateOpts.Labels = opts.Labels + *issueCreateOpts.Labels = gitlab.Labels(opts.Labels) issueCreateOpts.Description = &opts.Description if opts.IsConfidential { issueCreateOpts.Confidential = gitlab.Bool(opts.IsConfidential) diff --git a/commands/issue/list/issue_list.go b/commands/issue/list/issue_list.go index 655d25bc1..c91036ff2 100644 --- a/commands/issue/list/issue_list.go +++ b/commands/issue/list/issue_list.go @@ -192,11 +192,11 @@ func listRun(opts *ListOptions) error { opts.ListType = "search" } if len(opts.Labels) != 0 { - listOpts.Labels = opts.Labels + *listOpts.Labels = gitlab.Labels(opts.Labels) opts.ListType = "search" } if len(opts.NotLabels) != 0 { - listOpts.NotLabels = opts.NotLabels + *listOpts.NotLabels = gitlab.Labels(opts.NotLabels) opts.ListType = "search" } if opts.Milestone != "" { diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index ba8d96688..1ba479e5c 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -85,11 +85,11 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } if m, _ := cmd.Flags().GetStringSlice("label"); len(m) != 0 { actions = append(actions, fmt.Sprintf("added labels %s", strings.Join(m, " "))) - l.AddLabels = gitlab.Labels(m) + *l.AddLabels = gitlab.Labels(m) } if m, _ := cmd.Flags().GetStringSlice("unlabel"); len(m) != 0 { actions = append(actions, fmt.Sprintf("removed labels %s", strings.Join(m, " "))) - l.RemoveLabels = gitlab.Labels(m) + *l.RemoveLabels = gitlab.Labels(m) } if m, _ := cmd.Flags().GetBool("public"); m { actions = append(actions, "made public") @@ -114,7 +114,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } } if cmd.Flags().Changed("unassign") { - l.AssigneeIDs = []int{0} // 0 or an empty int[] is the documented way to unassign + l.AssigneeIDs = &[]int{0} // 0 or an empty int[] is the documented way to unassign actions = append(actions, "unassigned all users") } if ua != nil { diff --git a/commands/mr/create/mr_create.go b/commands/mr/create/mr_create.go index 4cbe44d29..40111bcbb 100644 --- a/commands/mr/create/mr_create.go +++ b/commands/mr/create/mr_create.go @@ -285,7 +285,7 @@ func createRun(opts *CreateOpts) error { } if opts.CopyIssueLabels { - mrCreateOpts.Labels = issue.Labels + *mrCreateOpts.Labels = issue.Labels } opts.Description = fmt.Sprintf("Closes #%d", issue.IID) opts.Title = fmt.Sprintf("Resolve \"%s\"", issue.Title) @@ -500,7 +500,7 @@ func createRun(opts *CreateOpts) error { // These actions need to be done here, after the `Add metadata` prompt because // they are metadata that can be modified by the prompt - mrCreateOpts.Labels = append(mrCreateOpts.Labels, opts.Labels...) + *mrCreateOpts.Labels = append(*mrCreateOpts.Labels, opts.Labels...) if len(opts.Assignees) > 0 { users, err := api.UsersByNames(labClient, opts.Assignees) diff --git a/commands/mr/for/mr_for.go b/commands/mr/for/mr_for.go index 4df2ca7db..34b1c196f 100644 --- a/commands/mr/for/mr_for.go +++ b/commands/mr/for/mr_for.go @@ -105,7 +105,7 @@ func NewCmdFor(f *cmdutils.Factory) *cobra.Command { l := &gitlab.CreateMergeRequestOptions{} l.Title = gitlab.String(mergeTitle) l.Description = gitlab.String(fmt.Sprintf("Closes #%d", issue.IID)) - l.Labels = gitlab.Labels{mergeLabel} + *l.Labels = gitlab.Labels{mergeLabel} l.SourceBranch = gitlab.String(sourceBranch) l.TargetBranch = gitlab.String(targetBranch) if milestone, _ := cmd.Flags().GetInt("milestone"); milestone != -1 { @@ -118,7 +118,7 @@ func NewCmdFor(f *cmdutils.Factory) *cobra.Command { l.RemoveSourceBranch = gitlab.Bool(true) } if withLables, _ := cmd.Flags().GetBool("with-labels"); withLables { - l.Labels = issue.Labels + *l.Labels = issue.Labels } if a, _ := cmd.Flags().GetString("assignee"); a != "" { @@ -129,7 +129,7 @@ func NewCmdFor(f *cmdutils.Factory) *cobra.Command { j := utils.StringToInt(i) t2 = append(t2, j) } - l.AssigneeIDs = t2 + l.AssigneeIDs = &t2 } mr, err := api.CreateMR(apiClient, repo.FullName(), l) diff --git a/commands/mr/list/mr_list.go b/commands/mr/list/mr_list.go index 655aaa8c8..4ba2a6730 100644 --- a/commands/mr/list/mr_list.go +++ b/commands/mr/list/mr_list.go @@ -181,7 +181,7 @@ func listRun(opts *ListOptions) error { opts.ListType = "search" } if len(opts.Labels) > 0 { - l.Labels = opts.Labels + *l.Labels = gitlab.Labels(opts.Labels) opts.ListType = "search" } if opts.Milestone != "" { diff --git a/commands/mr/update/mr_update.go b/commands/mr/update/mr_update.go index 6aaabeb7d..c1870430b 100644 --- a/commands/mr/update/mr_update.go +++ b/commands/mr/update/mr_update.go @@ -131,11 +131,11 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { if m, _ := cmd.Flags().GetStringSlice("label"); len(m) != 0 { actions = append(actions, fmt.Sprintf("added labels %s", strings.Join(m, " "))) - l.AddLabels = gitlab.Labels(m) + *l.AddLabels = gitlab.Labels(m) } if m, _ := cmd.Flags().GetStringSlice("unlabel"); len(m) != 0 { actions = append(actions, fmt.Sprintf("removed labels %s", strings.Join(m, " "))) - l.RemoveLabels = gitlab.Labels(m) + *l.RemoveLabels = gitlab.Labels(m) } if m, _ := cmd.Flags().GetString("target-branch"); m != "" { actions = append(actions, fmt.Sprintf("set target branch to %q", m)) @@ -156,7 +156,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } } if cmd.Flags().Changed("unassign") { - l.AssigneeIDs = []int{0} // 0 or an empty int[] is the documented way to unassign + l.AssigneeIDs = &[]int{0} // 0 or an empty int[] is the documented way to unassign actions = append(actions, "unassigned all users") } if ua != nil { diff --git a/commands/release/create/create.go b/commands/release/create/create.go index e9e448d6b..0b396ad45 100644 --- a/commands/release/create/create.go +++ b/commands/release/create/create.go @@ -337,7 +337,7 @@ func createRun(opts *CreateOpts) error { } if len(opts.Milestone) > 0 { - createOpts.Milestones = opts.Milestone + createOpts.Milestones = &opts.Milestone } release, _, err = client.Releases.CreateRelease(repo.FullName(), createOpts) @@ -362,7 +362,7 @@ func createRun(opts *CreateOpts) error { } if len(opts.Milestone) > 0 { - updateOpts.Milestones = opts.Milestone + updateOpts.Milestones = &opts.Milestone } release, _, err = client.Releases.UpdateRelease(repo.FullName(), opts.TagName, updateOpts) From 925c168bade5964fec4a3bf1437406b0ee8879ce Mon Sep 17 00:00:00 2001 From: Alberts Zemzale Date: Thu, 17 Mar 2022 20:21:34 +0200 Subject: [PATCH 7/7] refactor(cmdutils): Use the now correct way how to unassigne everyone --- commands/cmdutils/cmdutils_test.go | 4 ++-- commands/issue/update/issue_update.go | 2 +- commands/mr/update/mr_update.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/cmdutils/cmdutils_test.go b/commands/cmdutils/cmdutils_test.go index 590932ea7..c3d6b3879 100644 --- a/commands/cmdutils/cmdutils_test.go +++ b/commands/cmdutils/cmdutils_test.go @@ -323,7 +323,7 @@ func Test_UsersFromAddRemove(t *testing.T) { Username: "foo", }, }, - expectedIDs: []int{0}, + expectedIDs: nil, expectedAction: []string{`unassigned "@foo"`}, ua: UserAssignments{ToRemove: []string{"foo"}}, }, @@ -385,7 +385,7 @@ func Test_UsersFromAddRemove(t *testing.T) { Username: "foo", }, }, - expectedIDs: []int{0}, + expectedIDs: nil, expectedAction: []string{`unassigned "@foo"`}, ua: UserAssignments{ToRemove: []string{"foo"}}, }, diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 1ba479e5c..3d05913b1 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -114,7 +114,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } } if cmd.Flags().Changed("unassign") { - l.AssigneeIDs = &[]int{0} // 0 or an empty int[] is the documented way to unassign + l.AssigneeIDs = nil actions = append(actions, "unassigned all users") } if ua != nil { diff --git a/commands/mr/update/mr_update.go b/commands/mr/update/mr_update.go index c1870430b..174d56b32 100644 --- a/commands/mr/update/mr_update.go +++ b/commands/mr/update/mr_update.go @@ -156,7 +156,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } } if cmd.Flags().Changed("unassign") { - l.AssigneeIDs = &[]int{0} // 0 or an empty int[] is the documented way to unassign + l.AssigneeIDs = nil actions = append(actions, "unassigned all users") } if ua != nil {