Skip to content

Commit

Permalink
feat: add 'default_branch' attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jgangemi committed Oct 10, 2024
1 parent 6c05c53 commit d0900c2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
54 changes: 52 additions & 2 deletions groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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{})
if err != nil {
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)
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d0900c2

Please sign in to comment.