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

Commit d0900c2

Browse files
committed
feat: add 'default_branch' attribute
1 parent 6c05c53 commit d0900c2

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

groups.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Group struct {
4646
MembershipLock bool `json:"membership_lock"`
4747
Visibility VisibilityValue `json:"visibility"`
4848
LFSEnabled bool `json:"lfs_enabled"`
49+
DefaultBranch string `json:"default_branch"`
4950
DefaultBranchProtectionDefaults struct {
5051
AllowedToPush []*GroupAccessLevel `json:"allowed_to_push"`
5152
AllowForcePush bool `json:"allow_force_push"`
@@ -358,6 +359,7 @@ type CreateGroupOptions struct {
358359
Name *string `url:"name,omitempty" json:"name,omitempty"`
359360
Path *string `url:"path,omitempty" json:"path,omitempty"`
360361
Avatar *GroupAvatar `url:"-" json:"-"`
362+
DefaultBranch *string `url:"default_branch, omitempty" json:"default_branch,omitempty"`
361363
Description *string `url:"description,omitempty" json:"description,omitempty"`
362364
MembershipLock *bool `url:"membership_lock,omitempty" json:"membership_lock,omitempty"`
363365
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
@@ -502,6 +504,7 @@ type UpdateGroupOptions struct {
502504
Name *string `url:"name,omitempty" json:"name,omitempty"`
503505
Path *string `url:"path,omitempty" json:"path,omitempty"`
504506
Avatar *GroupAvatar `url:"-" json:"avatar,omitempty"`
507+
DefaultBranch *string `url:"default_branch,omitempty" json:"default_branch,omitempty"`
505508
Description *string `url:"description,omitempty" json:"description,omitempty"`
506509
MembershipLock *bool `url:"membership_lock,omitempty" json:"membership_lock,omitempty"`
507510
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`

groups_test.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ func TestGetGroup(t *testing.T) {
3838
mux.HandleFunc("/api/v4/groups/g",
3939
func(w http.ResponseWriter, r *http.Request) {
4040
testMethod(t, r, http.MethodGet)
41-
fmt.Fprint(w, `{"id": 1, "name": "g"}`)
41+
fmt.Fprint(w, `{"id": 1, "name": "g", "default_branch": "branch"}`)
4242
})
4343

4444
group, _, err := client.Groups.GetGroup("g", &GetGroupOptions{})
4545
if err != nil {
4646
t.Errorf("Groups.GetGroup returned error: %v", err)
4747
}
4848

49-
want := &Group{ID: 1, Name: "g"}
49+
want := &Group{ID: 1, Name: "g", DefaultBranch: "branch"}
5050
if !reflect.DeepEqual(want, group) {
5151
t.Errorf("Groups.GetGroup returned %+v, want %+v", group, want)
5252
}
@@ -97,6 +97,32 @@ func TestCreateGroup(t *testing.T) {
9797
}
9898
}
9999

100+
func TestCreateGroupWithDefaultBranch(t *testing.T) {
101+
mux, client := setup(t)
102+
103+
mux.HandleFunc("/api/v4/groups",
104+
func(w http.ResponseWriter, r *http.Request) {
105+
testMethod(t, r, http.MethodPost)
106+
fmt.Fprint(w, `{"id": 1, "name": "g", "path": "g", "default_branch": "branch"}`)
107+
})
108+
109+
opt := &CreateGroupOptions{
110+
Name: Ptr("g"),
111+
Path: Ptr("g"),
112+
DefaultBranch: Ptr("branch"),
113+
}
114+
115+
group, _, err := client.Groups.CreateGroup(opt, nil)
116+
if err != nil {
117+
t.Errorf("Groups.CreateGroup returned error: %v", err)
118+
}
119+
120+
want := &Group{ID: 1, Name: "g", Path: "g", DefaultBranch: "branch"}
121+
if !reflect.DeepEqual(want, group) {
122+
t.Errorf("Groups.CreateGroup returned %+v, want %+v", group, want)
123+
}
124+
}
125+
100126
func TestCreateGroupDefaultBranchSettings(t *testing.T) {
101127
mux, client := setup(t)
102128

@@ -326,6 +352,30 @@ func TestUpdateGroup(t *testing.T) {
326352
}
327353
}
328354

355+
func TestUpdateGroupWithDefaultBranch(t *testing.T) {
356+
mux, client := setup(t)
357+
358+
mux.HandleFunc("/api/v4/groups/1",
359+
func(w http.ResponseWriter, r *http.Request) {
360+
testMethod(t, r, http.MethodPut)
361+
fmt.Fprint(w, `{"id": 1, "default_branch": "branch"}`)
362+
})
363+
364+
opt := &UpdateGroupOptions{
365+
DefaultBranch: Ptr("branch"),
366+
}
367+
368+
group, _, err := client.Groups.UpdateGroup(1, opt)
369+
if err != nil {
370+
t.Errorf("Groups.UpdateGroup returned error: %v", err)
371+
}
372+
373+
want := &Group{ID: 1, DefaultBranch: "branch"}
374+
if !reflect.DeepEqual(want, group) {
375+
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
376+
}
377+
}
378+
329379
func TestListGroupProjects(t *testing.T) {
330380
mux, client := setup(t)
331381

0 commit comments

Comments
 (0)