Skip to content

Commit a1435f4

Browse files
authored
Merge pull request #201 from 20uf/feat/add-approvals
Add approvals, approve & unapprove API's
2 parents a7bfdc3 + 16c6de6 commit a1435f4

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

lib/Gitlab/Api/MergeRequests.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,37 @@ public function commits($project_id, $mr_id)
218218
{
219219
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/commits'));
220220
}
221+
222+
/**
223+
* @param int $project_id
224+
* @param int $mr_id
225+
*
226+
* @return mixed
227+
*/
228+
public function approvals($project_id, $mr_id)
229+
{
230+
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/approvals'));
231+
}
232+
233+
/**
234+
* @param int $project_id
235+
* @param int $mr_id
236+
*
237+
* @return mixed
238+
*/
239+
public function approve($project_id, $mr_id)
240+
{
241+
return $this->post($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/approve'));
242+
}
243+
244+
/**
245+
* @param int $project_id
246+
* @param int $mr_id
247+
*
248+
* @return mixed
249+
*/
250+
public function unApprove($project_id, $mr_id)
251+
{
252+
return $this->post($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/unapprove'));
253+
}
221254
}

test/Gitlab/Tests/Api/MergeRequestsTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,58 @@ public function shouldGetMergeRequestByIid()
353353
$this->assertEquals($expectedArray, $api->getByIid(1, 2));
354354
}
355355

356+
/**
357+
* @test
358+
*/
359+
public function shouldApproveMergeRequest()
360+
{
361+
$expectedArray = array('id' => 1, 'title' => 'Approvals API');
362+
363+
$api = $this->getApiMock();
364+
$api->expects($this->once())
365+
->method('post')
366+
->with('projects/1/merge_requests/2/approve')
367+
->will($this->returnValue($expectedArray))
368+
;
369+
370+
$this->assertEquals($expectedArray, $api->approve(1, 2));
371+
}
372+
373+
/**
374+
* @test
375+
*/
376+
public function shouldUnApproveMergeRequest()
377+
{
378+
$expectedArray = array('id' => 1, 'title' => 'Approvals API');
379+
380+
$api = $this->getApiMock();
381+
$api->expects($this->once())
382+
->method('post')
383+
->with('projects/1/merge_requests/2/unapprove')
384+
->will($this->returnValue($expectedArray))
385+
;
386+
387+
$this->assertEquals($expectedArray, $api->unapprove(1, 2));
388+
}
389+
390+
/**
391+
* @test
392+
*/
393+
public function shouldGetMergeRequestApprovals()
394+
{
395+
$expectedArray = array('id' => 1, 'title' => 'Approvals API');
396+
397+
$api = $this->getApiMock();
398+
$api->expects($this->once())
399+
->method('get')
400+
->with('projects/1/merge_requests', array('iid' => 2))
401+
->will($this->returnValue($expectedArray))
402+
;
403+
404+
$this->assertEquals($expectedArray, $api->getByIid(1, 2));
405+
}
406+
407+
356408
protected function getMultipleMergeRequestsData()
357409
{
358410
return array(

0 commit comments

Comments
 (0)