From 16c6de6498cb646e0b036c55ae76a3405d9d45a4 Mon Sep 17 00:00:00 2001 From: Michael COULLERET Date: Mon, 10 Jul 2017 12:02:59 +0200 Subject: [PATCH] Add approvals, approve & unapprove API's --- lib/Gitlab/Api/MergeRequests.php | 33 +++++++++++++ test/Gitlab/Tests/Api/MergeRequestsTest.php | 52 +++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/lib/Gitlab/Api/MergeRequests.php b/lib/Gitlab/Api/MergeRequests.php index 2d6dc6184..a4f1e2522 100644 --- a/lib/Gitlab/Api/MergeRequests.php +++ b/lib/Gitlab/Api/MergeRequests.php @@ -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) + { + 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) + { + 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) + { + return $this->post($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/unapprove')); + } } diff --git a/test/Gitlab/Tests/Api/MergeRequestsTest.php b/test/Gitlab/Tests/Api/MergeRequestsTest.php index bd6e6eb2b..c1e2181ea 100644 --- a/test/Gitlab/Tests/Api/MergeRequestsTest.php +++ b/test/Gitlab/Tests/Api/MergeRequestsTest.php @@ -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(