Skip to content

Add approvals, approve & unapprove API's #201

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

Merged
merged 1 commit into from
Jul 17, 2017
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
33 changes: 33 additions & 0 deletions lib/Gitlab/Api/MergeRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,37 @@ public function commits($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/commits'));
}

/**
* @param int $project_id
* @param int $mr_id
*
* @return mixed
*/
public function approvals($project_id, $mr_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use $merge_request_iid here instead of $mr_id? Full names are better than abbreviations and iid as it carry some information to the API user.

{
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/approvals'));
}

/**
* @param int $project_id
* @param int $mr_id
*
* @return mixed
*/
public function approve($project_id, $mr_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for $mr_id.

{
return $this->post($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/approve'));
}

/**
* @param int $project_id
* @param int $mr_id
*
* @return mixed
*/
public function unApprove($project_id, $mr_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unapprove here please. Also use $merge_request_iid.

{
return $this->post($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/unapprove'));
}
}
52 changes: 52 additions & 0 deletions test/Gitlab/Tests/Api/MergeRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,58 @@ public function shouldGetMergeRequestByIid()
$this->assertEquals($expectedArray, $api->getByIid(1, 2));
}

/**
* @test
*/
public function shouldApproveMergeRequest()
{
$expectedArray = array('id' => 1, 'title' => 'Approvals API');

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/merge_requests/2/approve')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->approve(1, 2));
}

/**
* @test
*/
public function shouldUnApproveMergeRequest()
{
$expectedArray = array('id' => 1, 'title' => 'Approvals API');

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/merge_requests/2/unapprove')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->unapprove(1, 2));
}

/**
* @test
*/
public function shouldGetMergeRequestApprovals()
{
$expectedArray = array('id' => 1, 'title' => 'Approvals API');

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/merge_requests', array('iid' => 2))
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->getByIid(1, 2));
}


protected function getMultipleMergeRequestsData()
{
return array(
Expand Down