Repository: xanzy/go-gitlab
Pull request #1589 (2022-12-02 17:31:38)

Add support for group ip restriction ranges
Closes: #1588


Patch:
diff --git a/groups.go b/groups.go
index 5280493..1f5d373 100644
--- a/groups.go
+++ b/groups.go
@@ -84,6 +84,7 @@ type Group struct {
 	PreventForkingOutsideGroup     bool             `json:"prevent_forking_outside_group"`
 	MarkedForDeletionOn            *ISOTime         `json:"marked_for_deletion_on"`
 	CreatedAt                      *time.Time       `json:"created_at"`
+	IPRestrictionRanges            string           `json:"ip_restriction_ranges"`
 }
 
 // GroupAvatar represents a GitLab group avatar.
@@ -351,6 +352,7 @@ type CreateGroupOptions struct {
 	ParentID                       *int                        `url:"parent_id,omitempty" json:"parent_id,omitempty"`
 	SharedRunnersMinutesLimit      *int                        `url:"shared_runners_minutes_limit,omitempty" json:"shared_runners_minutes_limit,omitempty"`
 	ExtraSharedRunnersMinutesLimit *int                        `url:"extra_shared_runners_minutes_limit,omitempty" json:"extra_shared_runners_minutes_limit,omitempty"`
+	IPRestrictionRanges            *string                     `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
 }
 
 // CreateGroup creates a new project group. Available only for users who can
@@ -478,6 +480,7 @@ type UpdateGroupOptions struct {
 	PreventForkingOutsideGroup           *bool                       `url:"prevent_forking_outside_group,omitempty" json:"prevent_forking_outside_group,omitempty"`
 	SharedRunnersSetting                 *SharedRunnersSettingValue  `url:"shared_runners_setting,omitempty" json:"shared_runners_setting,omitempty"`
 	PreventSharingGroupsOutsideHierarchy *bool                       `url:"prevent_sharing_groups_outside_hierarchy,omitempty" json:"prevent_sharing_groups_outside_hierarchy,omitempty"`
+	IPRestrictionRanges                  *string                     `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
 }
 
 // UpdateGroup updates an existing group; only available to group owners and


Test patch:
diff --git a/groups_test.go b/groups_test.go
index 0ab7b6b..5b1a4b2 100644
--- a/groups_test.go
+++ b/groups_test.go
@@ -522,3 +522,53 @@ func TestUnshareGroupFromGroup(t *testing.T) {
 		t.Errorf("Groups.UnshareGroupFromGroup returned status code %d", r.StatusCode)
 	}
 }
+
+func TestCreateGroupWithIPRestrictionRanges(t *testing.T) {
+	mux, server, client := setup(t)
+	defer teardown(server)
+
+	mux.HandleFunc("/api/v4/groups",
+		func(w http.ResponseWriter, r *http.Request) {
+			testMethod(t, r, http.MethodPost)
+			fmt.Fprint(w, `{"id": 1, "name": "g", "path": "g", "ip_restriction_ranges" : "192.168.0.0/24"}`)
+		})
+
+	opt := &CreateGroupOptions{
+		Name:                String("g"),
+		Path:                String("g"),
+		IPRestrictionRanges: String("192.168.0.0/24"),
+	}
+
+	group, _, err := client.Groups.CreateGroup(opt, nil)
+	if err != nil {
+		t.Errorf("Groups.CreateGroup returned error: %v", err)
+	}
+
+	want := &Group{ID: 1, Name: "g", Path: "g", IPRestrictionRanges: "192.168.0.0/24"}
+	if !reflect.DeepEqual(want, group) {
+		t.Errorf("Groups.CreateGroup returned %+v, want %+v", group, want)
+	}
+}
+
+func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) {
+	mux, server, client := setup(t)
+	defer teardown(server)
+
+	mux.HandleFunc("/api/v4/groups/1",
+		func(w http.ResponseWriter, r *http.Request) {
+			testMethod(t, r, http.MethodPut)
+			fmt.Fprint(w, `{"id": 1, "ip_restriction_ranges" : "192.168.0.0/24"}`)
+		})
+
+	group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{
+		IPRestrictionRanges: String("192.168.0.0/24"),
+	})
+	if err != nil {
+		t.Errorf("Groups.UpdateGroup returned error: %v", err)
+	}
+
+	want := &Group{ID: 1, IPRestrictionRanges: "192.168.0.0/24"}
+	if !reflect.DeepEqual(want, group) {
+		t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
+	}
+}