From 2572a74dcdc49a9d53d1bdff73daf1707ef6a51a Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 28 Oct 2024 09:21:20 +0100 Subject: [PATCH] Fix the update labels method --- labels.go | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/labels.go b/labels.go index d36e85b08..30d291994 100644 --- a/labels.go +++ b/labels.go @@ -108,12 +108,12 @@ func (s *LabelsService) ListLabels(pid interface{}, opt *ListLabelsOptions, opti // GetLabel get a single label for a given project. // // GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#get-a-single-project-label -func (s *LabelsService) GetLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Label, *Response, error) { +func (s *LabelsService) GetLabel(pid interface{}, lid interface{}, options ...RequestOptionFunc) (*Label, *Response, error) { project, err := parseID(pid) if err != nil { return nil, nil, err } - label, err := parseID(labelID) + label, err := parseID(lid) if err != nil { return nil, nil, err } @@ -183,15 +183,11 @@ func (s *LabelsService) DeleteLabel(pid interface{}, lid interface{}, opt *Delet if err != nil { return nil, err } - u := fmt.Sprintf("projects/%s/labels", PathEscape(project)) - - if lid != nil { - label, err := parseID(lid) - if err != nil { - return nil, err - } - u = fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label)) + label, err := parseID(lid) + if err != nil { + return nil, err } + u := fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label)) req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) if err != nil { @@ -205,7 +201,6 @@ func (s *LabelsService) DeleteLabel(pid interface{}, lid interface{}, opt *Delet // // GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#edit-an-existing-label type UpdateLabelOptions struct { - Name *string `url:"name,omitempty" json:"name,omitempty"` NewName *string `url:"new_name,omitempty" json:"new_name,omitempty"` Color *string `url:"color,omitempty" json:"color,omitempty"` Description *string `url:"description,omitempty" json:"description,omitempty"` @@ -216,12 +211,16 @@ type UpdateLabelOptions struct { // one parameter is required, to update the label. // // GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#edit-an-existing-label -func (s *LabelsService) UpdateLabel(pid interface{}, opt *UpdateLabelOptions, options ...RequestOptionFunc) (*Label, *Response, error) { +func (s *LabelsService) UpdateLabel(pid interface{}, lid interface{}, opt *UpdateLabelOptions, options ...RequestOptionFunc) (*Label, *Response, error) { project, err := parseID(pid) if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/labels", PathEscape(project)) + label, err := parseID(lid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label)) req, err := s.client.NewRequest(http.MethodPut, u, opt, options) if err != nil { @@ -243,12 +242,12 @@ func (s *LabelsService) UpdateLabel(pid interface{}, opt *UpdateLabelOptions, op // // GitLab API docs: // https://docs.gitlab.com/ee/api/labels.html#subscribe-to-a-label -func (s *LabelsService) SubscribeToLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Label, *Response, error) { +func (s *LabelsService) SubscribeToLabel(pid interface{}, lid interface{}, options ...RequestOptionFunc) (*Label, *Response, error) { project, err := parseID(pid) if err != nil { return nil, nil, err } - label, err := parseID(labelID) + label, err := parseID(lid) if err != nil { return nil, nil, err } @@ -274,12 +273,12 @@ func (s *LabelsService) SubscribeToLabel(pid interface{}, labelID interface{}, o // // GitLab API docs: // https://docs.gitlab.com/ee/api/labels.html#unsubscribe-from-a-label -func (s *LabelsService) UnsubscribeFromLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) { +func (s *LabelsService) UnsubscribeFromLabel(pid interface{}, lid interface{}, options ...RequestOptionFunc) (*Response, error) { project, err := parseID(pid) if err != nil { return nil, err } - label, err := parseID(labelID) + label, err := parseID(lid) if err != nil { return nil, err } @@ -297,12 +296,12 @@ func (s *LabelsService) UnsubscribeFromLabel(pid interface{}, labelID interface{ // // GitLab API docs: // https://docs.gitlab.com/ee/api/labels.html#promote-a-project-label-to-a-group-label -func (s *LabelsService) PromoteLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) { +func (s *LabelsService) PromoteLabel(pid interface{}, lid interface{}, options ...RequestOptionFunc) (*Response, error) { project, err := parseID(pid) if err != nil { return nil, err } - label, err := parseID(labelID) + label, err := parseID(lid) if err != nil { return nil, err }