From ac5b9b963d729f9574111f65c713edb85c3b41f7 Mon Sep 17 00:00:00 2001 From: Bonno van der Basch Date: Thu, 20 Feb 2020 16:23:55 +0100 Subject: [PATCH] Implement merge request API rebase endpoint The Gitlab merge request API added support for automatically rebasing the source_branch of the merge request against its target_branch (see: https://docs.gitlab.com/ee/api/merge_requests.html#rebase-a-merge-request). The code contained in this commit implements this feature. * Add Rebase MR API call * Add test for rebase MR --- lib/Gitlab/Api/MergeRequests.php | 15 +++++++++++++++ test/Gitlab/Tests/Api/MergeRequestsTest.php | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/Gitlab/Api/MergeRequests.php b/lib/Gitlab/Api/MergeRequests.php index a70361622..7d7481d1d 100644 --- a/lib/Gitlab/Api/MergeRequests.php +++ b/lib/Gitlab/Api/MergeRequests.php @@ -379,4 +379,19 @@ public function awardEmoji($project_id, $mr_iid) { return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_iid).'/award_emoji')); } + + /** + * @param int $project_id + * @param int $mr_id + * @param array $params + * @return mixed + */ + public function rebase($project_id, $mr_id, array $params = []) + { + $resolver = $this->createOptionsResolver(); + $resolver->setDefined('skip_ci') + ->setAllowedTypes('skip_ci', 'bool'); + + return $this->put($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id)).'/rebase', $resolver->resolve($params)); + } } diff --git a/test/Gitlab/Tests/Api/MergeRequestsTest.php b/test/Gitlab/Tests/Api/MergeRequestsTest.php index 0ecaea936..773cd388b 100644 --- a/test/Gitlab/Tests/Api/MergeRequestsTest.php +++ b/test/Gitlab/Tests/Api/MergeRequestsTest.php @@ -518,4 +518,23 @@ protected function getApiClass() { return 'Gitlab\Api\MergeRequests'; } + + /** + * @test + */ + public function shouldRebaseMergeRequest() + { + $expectedArray = array('rebase_in_progress' => true); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/merge_requests/2/rebase', array('skip_ci' => true)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->rebase(1, 2, array( + 'skip_ci' => true, + ))); + } }