Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Make it backwards compatible for now
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed Dec 9, 2023
1 parent cf6caff commit a49cd36
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
27 changes: 19 additions & 8 deletions group_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,32 @@ func (s *GroupLabelsService) CreateGroupLabel(gid interface{}, opt *CreateGroupL
return l, resp, nil
}

// DeleteGroupLabel deletes a group label given by its name.
// DeleteGroupLabelOptions represents the available DeleteGroupLabel() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_labels.html#delete-a-group-label
func (s *GroupLabelsService) DeleteGroupLabel(gid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) {
// GitLab API docs:
// 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 or ID.
//
// 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
}
label, err := parseID(labelID)
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))
}
u := fmt.Sprintf("groups/%s/labels/%s", PathEscape(group), PathEscape(label))

req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
Expand Down
21 changes: 19 additions & 2 deletions group_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,31 @@ 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")
_, 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) {
testMethod(t, r, http.MethodDelete)
})

label := &DeleteGroupLabelOptions{
Name: Ptr("My / GroupLabel"),
}

_, err := client.GroupLabels.DeleteGroupLabel("1", nil, label)
if err != nil {
log.Fatal(err)
}
Expand Down
25 changes: 18 additions & 7 deletions labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,32 @@ func (s *LabelsService) CreateLabel(pid interface{}, opt *CreateLabelOptions, op
return l, resp, nil
}

// DeleteLabel deletes a label given by its id.
// DeleteLabelOptions represents the available DeleteLabel() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#delete-a-label
func (s *LabelsService) DeleteLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) {
type DeleteLabelOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// 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{}, lid interface{}, opt *DeleteLabelOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
label, err := parseID(labelID)
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))
}
u := fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label))

req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
Expand Down
22 changes: 20 additions & 2 deletions labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,33 @@ 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")
_, 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) {
testMethod(t, r, http.MethodDelete)
})

// Delete label
label := &DeleteLabelOptions{
Name: Ptr("My Label"),
}

_, err := client.Labels.DeleteLabel("1", nil, label)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit a49cd36

Please sign in to comment.