From 18f1a0f245d85ee06b41f89edda6069210ee9a61 Mon Sep 17 00:00:00 2001 From: Jae Gangemi Date: Thu, 10 Oct 2024 09:20:39 -0600 Subject: [PATCH] feat: add 'default_branch' attribute --- groups.go | 3 +++ groups_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/groups.go b/groups.go index 34f0cab66..4576d1095 100644 --- a/groups.go +++ b/groups.go @@ -46,6 +46,7 @@ type Group struct { MembershipLock bool `json:"membership_lock"` Visibility VisibilityValue `json:"visibility"` LFSEnabled bool `json:"lfs_enabled"` + DefaultBranch string `json:"default_branch"` DefaultBranchProtectionDefaults struct { AllowedToPush []*GroupAccessLevel `json:"allowed_to_push"` AllowForcePush bool `json:"allow_force_push"` @@ -358,6 +359,7 @@ type CreateGroupOptions struct { Name *string `url:"name,omitempty" json:"name,omitempty"` Path *string `url:"path,omitempty" json:"path,omitempty"` Avatar *GroupAvatar `url:"-" json:"-"` + DefaultBranch *string `url:"default_branch,omitempty" json:"default_branch,omitempty"` Description *string `url:"description,omitempty" json:"description,omitempty"` MembershipLock *bool `url:"membership_lock,omitempty" json:"membership_lock,omitempty"` Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"` @@ -502,6 +504,7 @@ type UpdateGroupOptions struct { Name *string `url:"name,omitempty" json:"name,omitempty"` Path *string `url:"path,omitempty" json:"path,omitempty"` Avatar *GroupAvatar `url:"-" json:"avatar,omitempty"` + DefaultBranch *string `url:"default_branch,omitempty" json:"default_branch,omitempty"` Description *string `url:"description,omitempty" json:"description,omitempty"` MembershipLock *bool `url:"membership_lock,omitempty" json:"membership_lock,omitempty"` Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"` diff --git a/groups_test.go b/groups_test.go index 56eb8bbbb..d4e03c567 100644 --- a/groups_test.go +++ b/groups_test.go @@ -38,7 +38,7 @@ func TestGetGroup(t *testing.T) { mux.HandleFunc("/api/v4/groups/g", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodGet) - fmt.Fprint(w, `{"id": 1, "name": "g"}`) + fmt.Fprint(w, `{"id": 1, "name": "g", "default_branch": "branch"}`) }) group, _, err := client.Groups.GetGroup("g", &GetGroupOptions{}) @@ -46,7 +46,7 @@ func TestGetGroup(t *testing.T) { t.Errorf("Groups.GetGroup returned error: %v", err) } - want := &Group{ID: 1, Name: "g"} + want := &Group{ID: 1, Name: "g", DefaultBranch: "branch"} if !reflect.DeepEqual(want, group) { t.Errorf("Groups.GetGroup returned %+v, want %+v", group, want) } @@ -97,6 +97,32 @@ func TestCreateGroup(t *testing.T) { } } +func TestCreateGroupWithDefaultBranch(t *testing.T) { + mux, client := setup(t) + + 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", "default_branch": "branch"}`) + }) + + opt := &CreateGroupOptions{ + Name: Ptr("g"), + Path: Ptr("g"), + DefaultBranch: Ptr("branch"), + } + + 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", DefaultBranch: "branch"} + if !reflect.DeepEqual(want, group) { + t.Errorf("Groups.CreateGroup returned %+v, want %+v", group, want) + } +} + func TestCreateGroupDefaultBranchSettings(t *testing.T) { mux, client := setup(t) @@ -326,6 +352,30 @@ func TestUpdateGroup(t *testing.T) { } } +func TestUpdateGroupWithDefaultBranch(t *testing.T) { + mux, client := setup(t) + + mux.HandleFunc("/api/v4/groups/1", + func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPut) + fmt.Fprint(w, `{"id": 1, "default_branch": "branch"}`) + }) + + opt := &UpdateGroupOptions{ + DefaultBranch: Ptr("branch"), + } + + group, _, err := client.Groups.UpdateGroup(1, opt) + if err != nil { + t.Errorf("Groups.UpdateGroup returned error: %v", err) + } + + want := &Group{ID: 1, DefaultBranch: "branch"} + if !reflect.DeepEqual(want, group) { + t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want) + } +} + func TestListGroupProjects(t *testing.T) { mux, client := setup(t)