Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
bf34eca5
Commit
bf34eca5
authored
Dec 27, 2018
by
Sander van Harmelen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak the project MR approval methods
parent
38397d41
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
70 deletions
+64
-70
projects.go
projects.go
+39
-42
projects_test.go
projects_test.go
+25
-28
No files found.
projects.go
View file @
bf34eca5
...
...
@@ -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"`
}
// GetApproval
sConfigurationOptions get the approval configurations options for a given project on GitLab
.
// GetApproval
Configuration 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
)
GetApproval
sConfigurationOptions
(
pid
interface
{},
options
...
OptionFunc
)
(
*
ProjectApprovals
,
*
Response
,
error
)
{
func
(
s
*
ProjectsService
)
GetApproval
Configuration
(
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"`
}
// ChangeApproval
sConfigurationOptions updates the approval configurations for a given project on GitLab
.
// ChangeApproval
Configuration 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
)
ChangeApproval
sConfigurationOptions
(
pid
interface
{},
opt
*
Approvals
ConfigurationOptions
,
options
...
OptionFunc
)
(
*
ProjectApprovals
,
*
Response
,
error
)
{
func
(
s
*
ProjectsService
)
ChangeApproval
Configuration
(
pid
interface
{},
opt
*
ChangeApproval
ConfigurationOptions
,
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
}
projects_test.go
View file @
bf34eca5
...
...
@@ -352,41 +352,40 @@ func TestDeleteSharedProjectFromGroup(t *testing.T) {
}
}
func
TestGetApproval
sConfigurationOptions
(
t
*
testing
.
T
)
{
func
TestGetApproval
Configuration
(
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.GetApproval
sConfigurationOptions
returned error: %v"
,
err
)
t
.
Errorf
(
"Projects.GetApproval
Configuration
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.GetApproval
sConfigurationOptions
returned %+v, want %+v"
,
approvals
,
want
)
t
.
Errorf
(
"Projects.GetApproval
Configuration
returned %+v, want %+v"
,
approvals
,
want
)
}
}
func
TestChangeApproval
sConfigurationOptions
(
t
*
testing
.
T
)
{
func
TestChangeApproval
Configuration
(
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
:=
&
Approvals
ConfigurationOptions
{
opt
:=
&
ChangeApproval
ConfigurationOptions
{
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
TestChangeA
pproversConfigurationOption
s
(
t
*
testing
.
T
)
{
func
TestChangeA
llowedApprover
s
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
...
...
@@ -438,13 +436,12 @@ func TestChangeApproversConfigurationOptions(t *testing.T) {
}`
)
})
opt
:=
&
ApproversConfiguration
Options
{
opt
:=
&
ChangeAllowedApprovers
Options
{
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.ChangeA
pproversConfigurationOptions
returned %+v, want %+v"
,
approvals
,
want
)
t
.
Errorf
(
"Projects.ChangeA
llowedApprovers
returned %+v, want %+v"
,
approvals
,
want
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment