diff --git a/member_roles.go b/member_roles.go index a806afa73..d7efb9700 100644 --- a/member_roles.go +++ b/member_roles.go @@ -5,41 +5,48 @@ import ( "net/http" ) -const ( - GuestBaseLevel BaseAccessLevel = 10 -) - -type BaseAccessLevel int - +// MemberRolesService handles communication with the member roles related methods of +// the GitLab API. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/member_roles.html type MemberRolesService struct { client *Client } +// MemberRole represents a GitLab member role. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/member_roles.html type MemberRole struct { - ID int `json:"id"` - Name string `json:"name"` - Description string `json:"description,omitempty"` - GroupId int `json:"group_id"` - BaseAccessLevel int `json:"base_access_level"` - AdminMergeRequests bool `json:"admin_merge_requests,omitempty"` - AdminVulnerability bool `json:"admin_vulnerability,omitempty"` - ReadCode bool `json:"read_code,omitempty"` - ReadDependency bool `json:"read_dependency,omitempty"` - ReadVulnerability bool `json:"read_vulnerability,omitempty"` - ManageProjectAccessToken bool `json:"manage_project_access_token,omitempty"` + ID int `json:"id"` + Name string `json:"name"` + Description string `json:"description,omitempty"` + GroupId int `json:"group_id"` + BaseAccessLevel AccessLevelValue `json:"base_access_level"` + AdminMergeRequests bool `json:"admin_merge_requests,omitempty"` + AdminVulnerability bool `json:"admin_vulnerability,omitempty"` + ReadCode bool `json:"read_code,omitempty"` + ReadDependency bool `json:"read_dependency,omitempty"` + ReadVulnerability bool `json:"read_vulnerability,omitempty"` + ManageProjectAccessToken bool `json:"manage_project_access_token,omitempty"` } +// CreateMemberRoleOptions represents the available CreateMemberRole() options. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/member_roles.html#add-a-member-role-to-a-group type CreateMemberRoleOptions struct { - Name string `json:"name,"` - BaseAccessLevel BaseAccessLevel `json:"base_access_level"` - Description string `json:"description,omitempty"` - AdminMergeRequest bool `json:"admin_merge_request,omitempty"` - AdminVulnerability bool `json:"admin_vulnerability,omitempty"` - ReadCode bool `json:"read_code,omitempty"` - ReadDependency bool `json:"read_dependency,omitempty"` - ReadVulnerability bool `json:"read_vulnerability,omitempty"` + Name string `json:"name,"` + BaseAccessLevel AccessLevelValue `json:"base_access_level"` + Description string `json:"description,omitempty"` + AdminMergeRequest bool `json:"admin_merge_request,omitempty"` + AdminVulnerability bool `json:"admin_vulnerability,omitempty"` + ReadCode bool `json:"read_code,omitempty"` + ReadDependency bool `json:"read_dependency,omitempty"` + ReadVulnerability bool `json:"read_vulnerability,omitempty"` } +// ListMemberRoles gets a list of member roles for a specified group. +// +// Gitlab API docs: https://docs.gitlab.com/ee/api/member_roles.html#list-all-member-roles-of-a-group func (s *MemberRolesService) ListMemberRoles(groupId int, options ...RequestOptionFunc) ([]*MemberRole, *Response, error) { path := fmt.Sprintf("groups/%d/member_roles", groupId) req, err := s.client.NewRequest(http.MethodGet, path, nil, options) @@ -56,6 +63,9 @@ func (s *MemberRolesService) ListMemberRoles(groupId int, options ...RequestOpti return memberRoles, resp, nil } +// CreateMemberRole creates a new member role for a specified group. +// +// Gitlab API docs: https://docs.gitlab.com/ee/api/member_roles.html#add-a-member-role-to-a-group func (s *MemberRolesService) CreateMemberRole(groupId int, opt *CreateMemberRoleOptions, options ...RequestOptionFunc) (*MemberRole, *Response, error) { path := fmt.Sprintf("groups/%d/member_roles", groupId) req, err := s.client.NewRequest(http.MethodPost, path, opt, options) @@ -72,6 +82,9 @@ func (s *MemberRolesService) CreateMemberRole(groupId int, opt *CreateMemberRole return memberRole, resp, nil } +// DeleteMemberRole deletes a member role from a specified group. +// +// Gitlab API docs: https://docs.gitlab.com/ee/api/member_roles.html#remove-member-role-of-a-group func (s *MemberRolesService) DeleteMemberRole(groupId, memberRoleId int, options ...RequestOptionFunc) (*Response, error) { path := fmt.Sprintf("groups/%d/member_roles/%d", groupId, memberRoleId) req, err := s.client.NewRequest(http.MethodDelete, path, nil, options) diff --git a/member_roles_test.go b/member_roles_test.go index e5dfc8f50..00c72011b 100644 --- a/member_roles_test.go +++ b/member_roles_test.go @@ -64,7 +64,7 @@ func TestCreateMemberRole(t *testing.T) { memberRole, _, err := client.MemberRolesService.CreateMemberRole(84, &CreateMemberRoleOptions{ Name: "Custom guest", - BaseAccessLevel: 10, + BaseAccessLevel: GuestPermissions, Description: "a sample custom role", AdminMergeRequest: false, AdminVulnerability: false, @@ -78,7 +78,7 @@ func TestCreateMemberRole(t *testing.T) { ID: 3, Name: "Custom guest", Description: "a sample custom role", - BaseAccessLevel: 10, + BaseAccessLevel: GuestPermissions, GroupId: 84, AdminMergeRequests: false, AdminVulnerability: false,