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

Add permanently remove opt #1891

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,17 +560,25 @@ func (s *GroupsService) UploadAvatar(gid interface{}, avatar io.Reader, filename
return g, resp, nil
}

// DeleteGroupOptions represents the available DeleteGroup() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#update-group
type DeleteGroupOptions struct {
PermanentlyRemove *bool `url:"permanently_remove,omitempty" json:"permanently_remove,omitempty"`
FullPath *string `url:"full_path,omitempty" json:"full_path,omitempty"`
}

// DeleteGroup removes group with all projects inside.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#remove-group
func (s *GroupsService) DeleteGroup(gid interface{}, options ...RequestOptionFunc) (*Response, error) {
func (s *GroupsService) DeleteGroup(gid interface{}, opt *DeleteGroupOptions, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s", PathEscape(group))

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
45 changes: 44 additions & 1 deletion groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitlab
import (
"fmt"
"net/http"
"net/url"
"reflect"
"testing"
)
Expand Down Expand Up @@ -145,7 +146,7 @@ func TestDeleteGroup(t *testing.T) {
w.WriteHeader(http.StatusAccepted)
})

resp, err := client.Groups.DeleteGroup(1)
resp, err := client.Groups.DeleteGroup(1, nil)
if err != nil {
t.Errorf("Groups.DeleteGroup returned error: %v", err)
}
Expand All @@ -157,6 +158,48 @@ func TestDeleteGroup(t *testing.T) {
}
}

func TestDeleteGroup_WithPermanentDelete(t *testing.T) {
mux, client := setup(t)
var params url.Values

mux.HandleFunc("/api/v4/groups/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
w.WriteHeader(http.StatusAccepted)

// Get the request parameters
parsedParams, err := url.ParseQuery(r.URL.RawQuery)
if err != nil {
t.Errorf("Groups.DeleteGroup returned error when parsing test parameters: %v", err)
}
params = parsedParams
})

resp, err := client.Groups.DeleteGroup(1, &DeleteGroupOptions{
PermanentlyRemove: Ptr(true),
FullPath: Ptr("testPath"),
})

if err != nil {
t.Errorf("Groups.DeleteGroup returned error: %v", err)
}

// Test that our status code matches
if resp.StatusCode != http.StatusAccepted {
t.Errorf("Groups.DeleteGroup returned %d, want %d", resp.StatusCode, http.StatusAccepted)
}

// Test that "permanently_remove" is set to true
if params.Get("permanently_remove") != "true" {
t.Errorf("Groups.DeleteGroup returned %v, want %v", params.Get("permanently_remove"), true)
}

// Test that "full_path" is set to "testPath"
if params.Get("full_path") != "testPath" {
t.Errorf("Groups.DeleteGroup returned %v, want %v", params.Get("full_path"), "testPath")
}
}

func TestSearchGroup(t *testing.T) {
mux, client := setup(t)

Expand Down
Loading