Commit bf34eca5 authored by Sander van Harmelen's avatar Sander van Harmelen

Tweak the project MR approval methods

parent 38397d41
......@@ -1173,44 +1173,23 @@ func (s *ProjectsService) DeleteProjectPushRule(pid interface{}, options ...Opti
return s.client.Do(req, nil)
}
// ProjectApprovals represents GitLab project level merge request approvals.
// ProjectApprovals represents GitLab project level merge request approvals.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#project-level-mr-approvals
type ProjectApprovals struct {
Approvers []*MergeRequestApproverUser `json:"approvers"`
ApproverGroups []*MergeRequestApproverGroup `json:"approver_groups"`
ApprovalsBeforeMerge int `json:"approvals_before_merge"`
ResetApprovalsOnPush bool `json:"reset_approvals_on_push"`
DisableOverridingApproversPerMergeRequest bool `json:"disable_overriding_approvers_per_merge_request"`
Approvers []*MergeRequestApproverUser `json:"approvers"`
ApproverGroups []*MergeRequestApproverGroup `json:"approver_groups"`
}
// ApprovalsConfigurationOptions represents the available
// ApprovalsConfigurationOptions() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#change-configuration
type ApprovalsConfigurationOptions struct {
ApprovalsBeforeMerge *int `url:"approvals_before_merge,omitempty" json:"approvals_before_merge,omitempty"`
ResetApprovalsOnPush *bool `url:"reset_approvals_on_push,omitempty" json:"reset_approvals_on_push,omitempty"`
DisableOverridingApproversPerMergeRequest *bool `url:"disable_overriding_approvers_per_merge_request,omitempty" json:"disable_overriding_approvers_per_merge_request,omitempty"`
}
// ApproversConfigurationOptions represents the available
// ApproversConfigurationOptions() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#change-allowed-approvers
type ApproversConfigurationOptions struct {
ApproverIDs []*int `url:"approver_ids,omitempty" json:"approver_ids,omitempty"`
ApproverGroupIDs []*int `url:"approver_group_ids,omitempty" json:"approver_group_ids,omitempty"`
}
// GetApprovalsConfigurationOptions get the approval configurations options for a given project on GitLab.
// GetApprovalConfiguration get the approval configuration for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#get-configuration
func (s *ProjectsService) GetApprovalsConfigurationOptions(pid interface{}, options ...OptionFunc) (*ProjectApprovals, *Response, error) {
func (s *ProjectsService) GetApprovalConfiguration(pid interface{}, options ...OptionFunc) (*ProjectApprovals, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
......@@ -1222,21 +1201,31 @@ func (s *ProjectsService) GetApprovalsConfigurationOptions(pid interface{}, opti
return nil, nil, err
}
mrp := new(ProjectApprovals)
resp, err := s.client.Do(req, mrp)
pa := new(ProjectApprovals)
resp, err := s.client.Do(req, pa)
if err != nil {
return nil, resp, err
}
return mrp, resp, err
return pa, resp, err
}
// ChangeApprovalConfigurationOptions represents the available
// ApprovalConfiguration() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#change-configuration
type ChangeApprovalConfigurationOptions struct {
ApprovalsBeforeMerge *int `url:"approvals_before_merge,omitempty" json:"approvals_before_merge,omitempty"`
ResetApprovalsOnPush *bool `url:"reset_approvals_on_push,omitempty" json:"reset_approvals_on_push,omitempty"`
DisableOverridingApproversPerMergeRequest *bool `url:"disable_overriding_approvers_per_merge_request,omitempty" json:"disable_overriding_approvers_per_merge_request,omitempty"`
}
// ChangeApprovalsConfigurationOptions updates the approval configurations for a given project on GitLab.
// ChangeApprovalConfiguration updates the approval configuration for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#change-configuration
func (s *ProjectsService) ChangeApprovalsConfigurationOptions(pid interface{}, opt *ApprovalsConfigurationOptions, options ...OptionFunc) (*ProjectApprovals, *Response, error) {
func (s *ProjectsService) ChangeApprovalConfiguration(pid interface{}, opt *ChangeApprovalConfigurationOptions, options ...OptionFunc) (*ProjectApprovals, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
......@@ -1248,21 +1237,30 @@ func (s *ProjectsService) ChangeApprovalsConfigurationOptions(pid interface{}, o
return nil, nil, err
}
mrp := new(ProjectApprovals)
resp, err := s.client.Do(req, mrp)
pa := new(ProjectApprovals)
resp, err := s.client.Do(req, pa)
if err != nil {
return nil, resp, err
}
return mrp, resp, err
return pa, resp, err
}
// ChangeApproversConfigurationOptions updates the list of approvers for a given project on GitLab.
// ChangeAllowedApproversOptions represents the available ChangeAllowedApprovers()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#change-allowed-approvers
func (s *ProjectsService) ChangeApproversConfigurationOptions(pid interface{}, opt *ApproversConfigurationOptions, options ...OptionFunc) (*ProjectApprovals, *Response, error) {
type ChangeAllowedApproversOptions struct {
ApproverIDs []*int `url:"approver_ids,omitempty" json:"approver_ids,omitempty"`
ApproverGroupIDs []*int `url:"approver_group_ids,omitempty" json:"approver_group_ids,omitempty"`
}
// ChangeAllowedApprovers updates the list of approvers and approver groups.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#change-allowed-approvers
func (s *ProjectsService) ChangeAllowedApprovers(pid interface{}, opt *ChangeAllowedApproversOptions, options ...OptionFunc) (*ProjectApprovals, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
......@@ -1274,12 +1272,11 @@ func (s *ProjectsService) ChangeApproversConfigurationOptions(pid interface{}, o
return nil, nil, err
}
mrp := new(ProjectApprovals)
resp, err := s.client.Do(req, mrp)
pa := new(ProjectApprovals)
resp, err := s.client.Do(req, pa)
if err != nil {
return nil, resp, err
}
return mrp, resp, err
return pa, resp, err
}
......@@ -352,41 +352,40 @@ func TestDeleteSharedProjectFromGroup(t *testing.T) {
}
}
func TestGetApprovalsConfigurationOptions(t *testing.T) {
func TestGetApprovalConfiguration(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/approvals", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{
"approvers": [],
"approver_groups": [],
"approvals_before_merge": 3,
"reset_approvals_on_push": false,
"disable_overriding_approvers_per_merge_request": false,
"approvers": [],
"approver_groups": []
"disable_overriding_approvers_per_merge_request": false
}`)
})
approvals, _, err := client.Projects.GetApprovalsConfigurationOptions(1)
approvals, _, err := client.Projects.GetApprovalConfiguration(1)
if err != nil {
t.Errorf("Projects.GetApprovalsConfigurationOptions returned error: %v", err)
t.Errorf("Projects.GetApprovalConfiguration returned error: %v", err)
}
want := &ProjectApprovals{
ApprovalsBeforeMerge: 3,
ResetApprovalsOnPush: false,
Approvers: []*MergeRequestApproverUser{},
ApproverGroups: []*MergeRequestApproverGroup{},
ApprovalsBeforeMerge: 3,
ResetApprovalsOnPush: false,
DisableOverridingApproversPerMergeRequest: false,
Approvers: []*MergeRequestApproverUser{},
ApproverGroups: []*MergeRequestApproverGroup{},
}
if !reflect.DeepEqual(want, approvals) {
t.Errorf("Projects.GetApprovalsConfigurationOptions returned %+v, want %+v", approvals, want)
t.Errorf("Projects.GetApprovalConfiguration returned %+v, want %+v", approvals, want)
}
}
func TestChangeApprovalsConfigurationOptions(t *testing.T) {
func TestChangeApprovalConfiguration(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
......@@ -394,30 +393,29 @@ func TestChangeApprovalsConfigurationOptions(t *testing.T) {
testMethod(t, r, "POST")
testBody(t, r, `{"approvals_before_merge":3}`)
fmt.Fprint(w, `{
"approvers": [],
"approver_groups": [],
"approvals_before_merge": 3,
"reset_approvals_on_push": false,
"disable_overriding_approvers_per_merge_request": false,
"approvers": [],
"approver_groups": []
"disable_overriding_approvers_per_merge_request": false
}`)
})
opt := &ApprovalsConfigurationOptions{
opt := &ChangeApprovalConfigurationOptions{
ApprovalsBeforeMerge: Int(3),
}
approvals, _, err := client.Projects.ChangeApprovalsConfigurationOptions(1, opt)
approvals, _, err := client.Projects.ChangeApprovalConfiguration(1, opt)
if err != nil {
t.Errorf("Projects.ChangeApprovalConfigurationOptions returned error: %v", err)
}
want := &ProjectApprovals{
ApprovalsBeforeMerge: 3,
ResetApprovalsOnPush: false,
Approvers: []*MergeRequestApproverUser{},
ApproverGroups: []*MergeRequestApproverGroup{},
ApprovalsBeforeMerge: 3,
ResetApprovalsOnPush: false,
DisableOverridingApproversPerMergeRequest: false,
Approvers: []*MergeRequestApproverUser{},
ApproverGroups: []*MergeRequestApproverGroup{},
}
if !reflect.DeepEqual(want, approvals) {
......@@ -425,7 +423,7 @@ func TestChangeApprovalsConfigurationOptions(t *testing.T) {
}
}
func TestChangeApproversConfigurationOptions(t *testing.T) {
func TestChangeAllowedApprovers(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
......@@ -438,13 +436,12 @@ func TestChangeApproversConfigurationOptions(t *testing.T) {
}`)
})
opt := &ApproversConfigurationOptions{
opt := &ChangeAllowedApproversOptions{
ApproverIDs: []*int{Int(1)},
ApproverGroupIDs: []*int{Int(2)},
}
approvals, _, err := client.Projects.ChangeApproversConfigurationOptions(1, opt)
approvals, _, err := client.Projects.ChangeAllowedApprovers(1, opt)
if err != nil {
t.Errorf("Projects.ChangeApproversConfigurationOptions returned error: %v", err)
}
......@@ -486,6 +483,6 @@ func TestChangeApproversConfigurationOptions(t *testing.T) {
}
if !reflect.DeepEqual(want, approvals) {
t.Errorf("Projects.ChangeApproversConfigurationOptions returned %+v, want %+v", approvals, want)
t.Errorf("Projects.ChangeAllowedApprovers returned %+v, want %+v", approvals, want)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment