diff --git a/group_labels.go b/group_labels.go index d19e3ed5a..5a390269b 100644 --- a/group_labels.go +++ b/group_labels.go @@ -142,16 +142,25 @@ func (s *GroupLabelsService) CreateGroupLabel(gid interface{}, opt *CreateGroupL // https://docs.gitlab.com/ee/api/group_labels.html#delete-a-group-label type DeleteGroupLabelOptions DeleteLabelOptions -// DeleteGroupLabel deletes a group label given by its name. +// DeleteGroupLabel deletes a group label given by its name or ID. // -// GitLab API docs: https://docs.gitlab.com/ee/api/group_labels.html#delete-a-group-label -func (s *GroupLabelsService) DeleteGroupLabel(gid interface{}, opt *DeleteGroupLabelOptions, options ...RequestOptionFunc) (*Response, error) { +// GitLab API docs: +// https://docs.gitlab.com/ee/api/group_labels.html#delete-a-group-label +func (s *GroupLabelsService) DeleteGroupLabel(gid interface{}, lid interface{}, opt *DeleteGroupLabelOptions, options ...RequestOptionFunc) (*Response, error) { group, err := parseID(gid) if err != nil { return nil, err } u := fmt.Sprintf("groups/%s/labels", PathEscape(group)) + if lid != nil { + label, err := parseID(lid) + if err != nil { + return nil, err + } + u = fmt.Sprintf("groups/%s/labels/%s", PathEscape(group), PathEscape(label)) + } + req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) if err != nil { return nil, err diff --git a/group_labels_test.go b/group_labels_test.go index c79ab7824..42c2a326e 100644 --- a/group_labels_test.go +++ b/group_labels_test.go @@ -46,7 +46,20 @@ func TestCreateGroupGroupLabel(t *testing.T) { } } -func TestDeleteGroupLabel(t *testing.T) { +func TestDeleteGroupLabelByID(t *testing.T) { + mux, client := setup(t) + + mux.HandleFunc("/api/v4/groups/1/labels/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodDelete) + }) + + _, err := client.GroupLabels.DeleteGroupLabel("1", "1", nil) + if err != nil { + log.Fatal(err) + } +} + +func TestDeleteGroupLabelByName(t *testing.T) { mux, client := setup(t) mux.HandleFunc("/api/v4/groups/1/labels", func(w http.ResponseWriter, r *http.Request) { @@ -57,7 +70,7 @@ func TestDeleteGroupLabel(t *testing.T) { Name: Ptr("My / GroupLabel"), } - _, err := client.GroupLabels.DeleteGroupLabel("1", label) + _, err := client.GroupLabels.DeleteGroupLabel("1", nil, label) if err != nil { log.Fatal(err) } diff --git a/labels.go b/labels.go index 42fc778c9..d36e85b08 100644 --- a/labels.go +++ b/labels.go @@ -175,16 +175,24 @@ type DeleteLabelOptions struct { Name *string `url:"name,omitempty" json:"name,omitempty"` } -// DeleteLabel deletes a label given by its name. +// DeleteLabel deletes a label given by its name or ID. // // GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#delete-a-label -func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions, options ...RequestOptionFunc) (*Response, error) { +func (s *LabelsService) DeleteLabel(pid interface{}, lid interface{}, opt *DeleteLabelOptions, options ...RequestOptionFunc) (*Response, error) { project, err := parseID(pid) 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)) + } + req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) if err != nil { return nil, err diff --git a/labels_test.go b/labels_test.go index 3abfe3aa4..81260b3e0 100644 --- a/labels_test.go +++ b/labels_test.go @@ -48,7 +48,21 @@ func TestCreateLabel(t *testing.T) { } } -func TestDeleteLabel(t *testing.T) { +func TestDeleteLabelbyID(t *testing.T) { + mux, client := setup(t) + + mux.HandleFunc("/api/v4/projects/1/labels/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodDelete) + }) + + // Delete label + _, err := client.Labels.DeleteLabel("1", "1", nil) + if err != nil { + log.Fatal(err) + } +} + +func TestDeleteLabelbyName(t *testing.T) { mux, client := setup(t) mux.HandleFunc("/api/v4/projects/1/labels", func(w http.ResponseWriter, r *http.Request) { @@ -60,7 +74,7 @@ func TestDeleteLabel(t *testing.T) { Name: Ptr("My Label"), } - _, err := client.Labels.DeleteLabel("1", label) + _, err := client.Labels.DeleteLabel("1", nil, label) if err != nil { log.Fatal(err) }