From 16b68a27aea7f3d325ed17b2fe646b3e08524c75 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 | 7 +++++++ tests/Api/RepositoriesTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Api/Repositories.php b/src/Api/Repositories.php index eded16b9..9a6c2a81 100644 --- a/src/Api/Repositories.php +++ b/src/Api/Repositories.php @@ -185,6 +185,13 @@ public function commitRefs(int|string $project_id, string $sha, array $parameter ); } + public function commitMergeRequests(int|string $project_id, string $sha): mixed + { + return $this->get( + $this->getProjectPath($project_id, 'repository/commits/'.self::encodePath($sha).'/merge_requests'), + ); + } + /** * @param array $parameters { * diff --git a/tests/Api/RepositoriesTest.php b/tests/Api/RepositoriesTest.php index 3b5d7334..e29e814b 100644 --- a/tests/Api/RepositoriesTest.php +++ b/tests/Api/RepositoriesTest.php @@ -328,6 +328,24 @@ 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] #[DataProvider('dataGetCommitRefsWithParams')] public function shouldGetCommitRefsWithParams(string $type, array $expectedArray): void