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

Commit

Permalink
Merge pull request #1196 from jguttman94/edit-group
Browse files Browse the repository at this point in the history
Add Edit Groups
  • Loading branch information
svanharmelen authored Aug 26, 2021
2 parents 65122af + 5c2574c commit 1a26625
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
53 changes: 53 additions & 0 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,59 @@ func (s *GroupsService) CreateGroup(opt *CreateGroupOptions, options ...RequestO
return g, resp, err
}

// EditGroupOptions represents the available EditGroup() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#update-group
type EditGroupOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Path *string `url:"path,omitempty" json:"path,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"`
ShareWithGroupLock *bool `url:"share_with_group_lock,omitempty" json:"share_with_group_lock,omitempty"`
RequireTwoFactorAuth *bool `url:"require_two_factor_authentication,omitempty" json:"require_two_factor_authentication,omitempty"`
TwoFactorGracePeriod *int `url:"two_factor_grace_period,omitempty" json:"two_factor_grace_period,omitempty"`
ProjectCreationLevel *ProjectCreationLevelValue `url:"project_creation_level,omitempty" json:"project_creation_level,omitempty"`
AutoDevopsEnabled *bool `url:"auto_devops_enabled,omitempty" json:"auto_devops_enabled,omitempty"`
SubGroupCreationLevel *SubGroupCreationLevelValue `url:"subgroup_creation_level,omitempty" json:"subgroup_creation_level,omitempty"`
EmailsDisabled *bool `url:"emails_disabled,omitempty" json:"emails_disabled,omitempty"`
MentionsDisabled *bool `url:"mentions_disabled,omitempty" json:"mentions_disabled,omitempty"`
LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"`
RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"`
DefaultBranchProtection *int `url:"default_branch_protection,omitempty" json:"default_branch_protection,omitempty"`
FileTemplateProjectID *int `url:"file_template_project_id,omitempty" json:"file_template_project_id,omitempty"`
SharedRunnersMinutesLimit *int `url:"shared_runners_minutes_limit,omitempty" json:"shared_runners_minutes_limit,omitempty"`
ExtraSharedRunnersMinutesLimit *int `url:"extra_shared_runners_minutes_limit,omitempty" json:"extra_shared_runners_minutes_limit,omitempty"`
PreventForkingOutsideGroup *bool `url:"prevent_forking_outside_group,omitempty" json:"prevent_forking_outside_group,omitempty"`
SharedRunnersSetting *SharedRunnersSettingValue `url:"shared_runners_setting,omitempty" json:"shared_runners_setting,omitempty"`
PreventSharingGroupsOutsideHierarchy *bool `url:"prevent_sharing_groups_outside_hierarchy,omitempty" json:"prevent_sharing_groups_outside_hierarchy,omitempty"`
}

// EditGroup updates an existing group. Only available to group owners
// and administrators.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#update-group
func (s *GroupsService) EditGroup(gid interface{}, opt *EditGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s", pathEscape(group))

req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}

g := new(Group)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}

return g, resp, err
}

// TransferGroup transfers a project to the Group namespace. Available only
// for admin.
//
Expand Down
26 changes: 26 additions & 0 deletions groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ func TestCreateGroup(t *testing.T) {
}
}

func TestEditGroup(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)

mux.HandleFunc("/api/v4/groups/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"id": 1, "name": "g", "path": "g"}`)
})

opt := &EditGroupOptions{
Name: String("g"),
Path: String("g"),
}

group, _, err := client.Groups.EditGroup(1, opt, nil)
if err != nil {
t.Errorf("Groups.EditGroup returned error: %v", err)
}

want := &Group{ID: 1, Name: "g", Path: "g"}
if !reflect.DeepEqual(want, group) {
t.Errorf("Groups.EditGroup returned %+v, want %+v", group, want)
}
}

func TestTransferGroup(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
Expand Down
22 changes: 22 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ func ProjectCreationLevel(v ProjectCreationLevelValue) *ProjectCreationLevelValu
return p
}

// SharedRunnersSettingValue represents whether shared runners are enabled for a group’s subgroups and projects.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#options-for-shared_runners_setting
type SharedRunnersSettingValue string

// List of available shared runner settings levels.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#options-for-shared_runners_setting
const (
EnabledSharedRunnersSettingValue SharedRunnersSettingValue = "enabled"
DisabledWithOverrideSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_with_override"
DisabledAndUnoverridableSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_and_unoverridable"
)

// SharedRunnersSetting is a helper routine that allocates a new SharedRunnersSettingValue
// to store v and returns a pointer to it.
func SharedRunnersSetting(v SharedRunnersSettingValue) *SharedRunnersSettingValue {
p := new(SharedRunnersSettingValue)
*p = v
return p
}

// SubGroupCreationLevelValue represents a sub group creation level within GitLab.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/
Expand Down

0 comments on commit 1a26625

Please sign in to comment.