Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation of merge_request_approval_state #565

Merged
merged 5 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/gitlab/client/merge_request_approvals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,17 @@ def approve_merge_request(project, merge_request, options = {})
def unapprove_merge_request(project, merge_request, options = {})
post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove", body: options)
end

# Get the approval state of merge requests
#
# @example
# Gitlab.merge_request_approval_state(5, 36)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of a merge request.
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_request_approval_state(project, id)
get("/projects/#{url_encode project}/merge_requests/#{id}/approval_state")
end
end
end
46 changes: 46 additions & 0 deletions spec/fixtures/merge_request_approval_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "Approvals API",
"description": "Test",
"state": "opened",
"created_at": "2016-06-08T00:19:52.638Z",
"updated_at": "2016-06-08T21:20:42.470Z",
"merge_status": "cannot_be_merged",
"approvals_required": 2,
"approvals_left": 2,
"approved_by": [],
"approvers": [
{
"user": {
"name": "Administrator",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon",
"web_url": "http://localhost:3000/root"
}
}
],
"approver_groups": [
{
"group": {
"id": 5,
"name": "group1",
"path": "group1",
"description": "",
"visibility": "public",
"lfs_enabled": false,
"avatar_url": null,
"web_url": "http://localhost/groups/group1",
"request_access_enabled": false,
"full_name": "group1",
"full_path": "group1",
"parent_id": null,
"ldap_cn": null,
"ldap_access": null
}
}
]
}
17 changes: 17 additions & 0 deletions spec/gitlab/client/merge_request_approvals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,21 @@
expect(a_post('/projects/1/merge_requests/5/unapprove')).to have_been_made
end
end

describe '.merge_request_approval_state' do
before do
stub_get('/projects/3/merge_requests/1/approval_state', 'merge_request_approval_state')
@approval_state = Gitlab.merge_request_approval_state(3, 1)
end

it 'gets the correct resource' do
expect(a_get('/projects/3/merge_requests/1/approval_state')).to have_been_made
end

it 'returns information about all approval states of merge request' do
expect(@approval_state.approvals_required).to eq(2)
expect(@approval_state.approvals_left).to eq(2)
expect(@approval_state.approved_by).to be_empty
end
end
end