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

Commit 56c0535

Browse files
authored
Merge pull request #2036 from xanzy/fix/settings
Fix the branch protection defaults
2 parents 39fc25b + 5538ce0 commit 56c0535

File tree

3 files changed

+457
-457
lines changed

3 files changed

+457
-457
lines changed

groups.go

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,38 @@ type GroupsService struct {
3939
//
4040
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html
4141
type Group struct {
42-
ID int `json:"id"`
43-
Name string `json:"name"`
44-
Path string `json:"path"`
45-
Description string `json:"description"`
46-
MembershipLock bool `json:"membership_lock"`
47-
Visibility VisibilityValue `json:"visibility"`
48-
LFSEnabled bool `json:"lfs_enabled"`
49-
DefaultBranch string `json:"default_branch"`
50-
DefaultBranchProtectionDefaults struct {
51-
AllowedToPush []*GroupAccessLevel `json:"allowed_to_push"`
52-
AllowForcePush bool `json:"allow_force_push"`
53-
AllowedToMerge []*GroupAccessLevel `json:"allowed_to_merge"`
54-
DeveloperCanInitialPush bool `json:"developer_can_initial_push"`
55-
} `json:"default_branch_protection_defaults"`
56-
AvatarURL string `json:"avatar_url"`
57-
WebURL string `json:"web_url"`
58-
RequestAccessEnabled bool `json:"request_access_enabled"`
59-
RepositoryStorage string `json:"repository_storage"`
60-
FullName string `json:"full_name"`
61-
FullPath string `json:"full_path"`
62-
FileTemplateProjectID int `json:"file_template_project_id"`
63-
ParentID int `json:"parent_id"`
64-
Projects []*Project `json:"projects"`
65-
Statistics *Statistics `json:"statistics"`
66-
CustomAttributes []*CustomAttribute `json:"custom_attributes"`
67-
ShareWithGroupLock bool `json:"share_with_group_lock"`
68-
RequireTwoFactorAuth bool `json:"require_two_factor_authentication"`
69-
TwoFactorGracePeriod int `json:"two_factor_grace_period"`
70-
ProjectCreationLevel ProjectCreationLevelValue `json:"project_creation_level"`
71-
AutoDevopsEnabled bool `json:"auto_devops_enabled"`
72-
SubGroupCreationLevel SubGroupCreationLevelValue `json:"subgroup_creation_level"`
73-
EmailsEnabled bool `json:"emails_enabled"`
74-
MentionsDisabled bool `json:"mentions_disabled"`
75-
RunnersToken string `json:"runners_token"`
76-
SharedProjects []*Project `json:"shared_projects"`
77-
SharedRunnersSetting SharedRunnersSettingValue `json:"shared_runners_setting"`
78-
SharedWithGroups []struct {
42+
ID int `json:"id"`
43+
Name string `json:"name"`
44+
Path string `json:"path"`
45+
Description string `json:"description"`
46+
MembershipLock bool `json:"membership_lock"`
47+
Visibility VisibilityValue `json:"visibility"`
48+
LFSEnabled bool `json:"lfs_enabled"`
49+
DefaultBranch string `json:"default_branch"`
50+
DefaultBranchProtectionDefaults *BranchProtectionDefaults `json:"default_branch_protection_defaults"`
51+
AvatarURL string `json:"avatar_url"`
52+
WebURL string `json:"web_url"`
53+
RequestAccessEnabled bool `json:"request_access_enabled"`
54+
RepositoryStorage string `json:"repository_storage"`
55+
FullName string `json:"full_name"`
56+
FullPath string `json:"full_path"`
57+
FileTemplateProjectID int `json:"file_template_project_id"`
58+
ParentID int `json:"parent_id"`
59+
Projects []*Project `json:"projects"`
60+
Statistics *Statistics `json:"statistics"`
61+
CustomAttributes []*CustomAttribute `json:"custom_attributes"`
62+
ShareWithGroupLock bool `json:"share_with_group_lock"`
63+
RequireTwoFactorAuth bool `json:"require_two_factor_authentication"`
64+
TwoFactorGracePeriod int `json:"two_factor_grace_period"`
65+
ProjectCreationLevel ProjectCreationLevelValue `json:"project_creation_level"`
66+
AutoDevopsEnabled bool `json:"auto_devops_enabled"`
67+
SubGroupCreationLevel SubGroupCreationLevelValue `json:"subgroup_creation_level"`
68+
EmailsEnabled bool `json:"emails_enabled"`
69+
MentionsDisabled bool `json:"mentions_disabled"`
70+
RunnersToken string `json:"runners_token"`
71+
SharedProjects []*Project `json:"shared_projects"`
72+
SharedRunnersSetting SharedRunnersSettingValue `json:"shared_runners_setting"`
73+
SharedWithGroups []struct {
7974
GroupID int `json:"group_id"`
8075
GroupName string `json:"group_name"`
8176
GroupFullPath string `json:"group_full_path"`
@@ -101,6 +96,17 @@ type Group struct {
10196
DefaultBranchProtection int `json:"default_branch_protection"`
10297
}
10398

99+
// BranchProtectionDefaults represents default Git protected branch permissions.
100+
//
101+
// GitLab API docs:
102+
// https://docs.gitlab.com/ee/api/groups.html#options-for-default_branch_protection_defaults
103+
type BranchProtectionDefaults struct {
104+
AllowedToPush []*GroupAccessLevel `json:"allowed_to_push,omitempty"`
105+
AllowForcePush bool `json:"allow_force_push,omitempty"`
106+
AllowedToMerge []*GroupAccessLevel `json:"allowed_to_merge,omitempty"`
107+
DeveloperCanInitialPush bool `json:"developer_can_initial_push,omitempty"`
108+
}
109+
104110
// GroupAccessLevel represents default branch protection defaults access levels.
105111
//
106112
// GitLab API docs:

groups_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,19 @@ func TestCreateGroupDefaultBranchSettings(t *testing.T) {
186186
ID: 1,
187187
Name: "g",
188188
Path: "g",
189+
DefaultBranchProtectionDefaults: &BranchProtectionDefaults{
190+
AllowedToMerge: []*GroupAccessLevel{
191+
{
192+
AccessLevel: Ptr(MaintainerPermissions),
193+
},
194+
},
195+
AllowedToPush: []*GroupAccessLevel{
196+
{
197+
AccessLevel: Ptr(MaintainerPermissions),
198+
},
199+
},
200+
},
189201
}
190-
want.DefaultBranchProtectionDefaults.AllowForcePush = false
191-
want.DefaultBranchProtectionDefaults.AllowedToMerge = []*GroupAccessLevel{{
192-
AccessLevel: Ptr(MaintainerPermissions),
193-
}}
194-
want.DefaultBranchProtectionDefaults.AllowedToPush = []*GroupAccessLevel{{
195-
AccessLevel: Ptr(MaintainerPermissions),
196-
}}
197202

198203
if !reflect.DeepEqual(want, group) {
199204
t.Errorf("Groups.CreateGroup returned %+v, want %+v", group, want)

0 commit comments

Comments
 (0)