From 139f66302eb131671d853669705daf0fd28627eb Mon Sep 17 00:00:00 2001 From: zluiten <1336070+zluiten@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:07:17 +0100 Subject: [PATCH] Add support for listing merge requests associated with a commit --- src/Api/Repositories.php | 13 +++++++++++++ tests/Api/RepositoriesTest.php | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Api/Repositories.php b/src/Api/Repositories.php index ac6f4f0f..551973fc 100644 --- a/src/Api/Repositories.php +++ b/src/Api/Repositories.php @@ -268,6 +268,19 @@ public function commitRefs($project_id, string $sha, array $parameters = []) ); } + /** + * @param int|string $project_id + * @param string $sha + * + * @return mixed + */ + public function commitMergeRequests($project_id, string $sha) + { + return $this->get( + $this->getProjectPath($project_id, 'repository/commits/'.self::encodePath($sha).'/merge_requests'), + ); + } + /** * @param int|string $project_id * @param array $parameters { diff --git a/tests/Api/RepositoriesTest.php b/tests/Api/RepositoriesTest.php index 67e9ceb8..ace58f30 100644 --- a/tests/Api/RepositoriesTest.php +++ b/tests/Api/RepositoriesTest.php @@ -361,6 +361,26 @@ public function shouldGetCommitRefs(): void $this->assertEquals($expectedArray, $api->commitRefs(1, 'abcd1234')); } + /** + * @test + */ + public function shouldGetCommitMergeRequests(): void + { + $expectedArray = [ + ['id' => 1, 'title' => 'A merge request'], + ['id' => 2, 'title' => 'Another merge request'], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits/abcd1234/merge_requests') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->commitMergeRequests(1, 'abcd1234')); + } + /** * @test *