Skip to content

Commit

Permalink
Fix the branch protection defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed Oct 14, 2024
1 parent f1dc012 commit 5538ce0
Show file tree
Hide file tree
Showing 3 changed files with 457 additions and 457 deletions.
80 changes: 43 additions & 37 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,38 @@ type GroupsService struct {
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html
type Group struct {
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Description string `json:"description"`
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"`
AllowedToMerge []*GroupAccessLevel `json:"allowed_to_merge"`
DeveloperCanInitialPush bool `json:"developer_can_initial_push"`
} `json:"default_branch_protection_defaults"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
RequestAccessEnabled bool `json:"request_access_enabled"`
RepositoryStorage string `json:"repository_storage"`
FullName string `json:"full_name"`
FullPath string `json:"full_path"`
FileTemplateProjectID int `json:"file_template_project_id"`
ParentID int `json:"parent_id"`
Projects []*Project `json:"projects"`
Statistics *Statistics `json:"statistics"`
CustomAttributes []*CustomAttribute `json:"custom_attributes"`
ShareWithGroupLock bool `json:"share_with_group_lock"`
RequireTwoFactorAuth bool `json:"require_two_factor_authentication"`
TwoFactorGracePeriod int `json:"two_factor_grace_period"`
ProjectCreationLevel ProjectCreationLevelValue `json:"project_creation_level"`
AutoDevopsEnabled bool `json:"auto_devops_enabled"`
SubGroupCreationLevel SubGroupCreationLevelValue `json:"subgroup_creation_level"`
EmailsEnabled bool `json:"emails_enabled"`
MentionsDisabled bool `json:"mentions_disabled"`
RunnersToken string `json:"runners_token"`
SharedProjects []*Project `json:"shared_projects"`
SharedRunnersSetting SharedRunnersSettingValue `json:"shared_runners_setting"`
SharedWithGroups []struct {
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Description string `json:"description"`
MembershipLock bool `json:"membership_lock"`
Visibility VisibilityValue `json:"visibility"`
LFSEnabled bool `json:"lfs_enabled"`
DefaultBranch string `json:"default_branch"`
DefaultBranchProtectionDefaults *BranchProtectionDefaults `json:"default_branch_protection_defaults"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
RequestAccessEnabled bool `json:"request_access_enabled"`
RepositoryStorage string `json:"repository_storage"`
FullName string `json:"full_name"`
FullPath string `json:"full_path"`
FileTemplateProjectID int `json:"file_template_project_id"`
ParentID int `json:"parent_id"`
Projects []*Project `json:"projects"`
Statistics *Statistics `json:"statistics"`
CustomAttributes []*CustomAttribute `json:"custom_attributes"`
ShareWithGroupLock bool `json:"share_with_group_lock"`
RequireTwoFactorAuth bool `json:"require_two_factor_authentication"`
TwoFactorGracePeriod int `json:"two_factor_grace_period"`
ProjectCreationLevel ProjectCreationLevelValue `json:"project_creation_level"`
AutoDevopsEnabled bool `json:"auto_devops_enabled"`
SubGroupCreationLevel SubGroupCreationLevelValue `json:"subgroup_creation_level"`
EmailsEnabled bool `json:"emails_enabled"`
MentionsDisabled bool `json:"mentions_disabled"`
RunnersToken string `json:"runners_token"`
SharedProjects []*Project `json:"shared_projects"`
SharedRunnersSetting SharedRunnersSettingValue `json:"shared_runners_setting"`
SharedWithGroups []struct {
GroupID int `json:"group_id"`
GroupName string `json:"group_name"`
GroupFullPath string `json:"group_full_path"`
Expand All @@ -101,6 +96,17 @@ type Group struct {
DefaultBranchProtection int `json:"default_branch_protection"`
}

// BranchProtectionDefaults represents default Git protected branch permissions.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#options-for-default_branch_protection_defaults
type BranchProtectionDefaults struct {
AllowedToPush []*GroupAccessLevel `json:"allowed_to_push,omitempty"`
AllowForcePush bool `json:"allow_force_push,omitempty"`
AllowedToMerge []*GroupAccessLevel `json:"allowed_to_merge,omitempty"`
DeveloperCanInitialPush bool `json:"developer_can_initial_push,omitempty"`
}

// GroupAccessLevel represents default branch protection defaults access levels.
//
// GitLab API docs:
Expand Down
19 changes: 12 additions & 7 deletions groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,19 @@ func TestCreateGroupDefaultBranchSettings(t *testing.T) {
ID: 1,
Name: "g",
Path: "g",
DefaultBranchProtectionDefaults: &BranchProtectionDefaults{
AllowedToMerge: []*GroupAccessLevel{
{
AccessLevel: Ptr(MaintainerPermissions),
},
},
AllowedToPush: []*GroupAccessLevel{
{
AccessLevel: Ptr(MaintainerPermissions),
},
},
},
}
want.DefaultBranchProtectionDefaults.AllowForcePush = false
want.DefaultBranchProtectionDefaults.AllowedToMerge = []*GroupAccessLevel{{
AccessLevel: Ptr(MaintainerPermissions),
}}
want.DefaultBranchProtectionDefaults.AllowedToPush = []*GroupAccessLevel{{
AccessLevel: Ptr(MaintainerPermissions),
}}

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

0 comments on commit 5538ce0

Please sign in to comment.