Repository: xanzy/go-gitlab
Pull request #1891 (2024-03-04 00:55:20)

Add permanently remove opt
Adds the "permanently_remove" option from the delete group API:

https://docs.gitlab.com/ee/api/groups.html#remove-group


Patch:
diff --git a/groups.go b/groups.go
index fcbd68d..1040684 100644
--- a/groups.go
+++ b/groups.go
@@ -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
 	}


Test patch:
diff --git a/groups_test.go b/groups_test.go
index b6f8e04..d848e74 100644
--- a/groups_test.go
+++ b/groups_test.go
@@ -3,6 +3,7 @@ package gitlab
 import (
 	"fmt"
 	"net/http"
+	"net/url"
 	"reflect"
 	"testing"
 )
@@ -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)
 	}
@@ -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)