diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 83d5b7d0..a6b6ba2d 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -368,4 +368,26 @@ public function deleteLevelRule(int|string $project_id, int $mr_iid, int $approv { return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/approval_rules/'.self::encodePath($approval_rule_id))); } + + public function createDependency(int|string $project_id, int $mr_iid, int $blocking_merge_request_id): mixed + { + return $this->post($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blocks'), [ + 'blocking_merge_request_id' => $blocking_merge_request_id, + ]); + } + + public function dependencies(int|string $project_id, int $mr_iid): mixed + { + return $this->get($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blocks')); + } + + public function deleteDependency(int|string $project_id, int $mr_iid, int $block_id): mixed + { + return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blocks/'.self::encodePath($block_id))); + } + + public function blockedMrs(int|string $project_id, int $mr_iid): mixed + { + return $this->get($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blockees')); + } } diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index c0803014..9b7c93a9 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -822,4 +822,69 @@ public function shouldRebaseMergeRequest(): void 'skip_ci' => true, ])); } + + #[Test] + public function shouldCreateDependency(): void + { + $expectedArray = ['id' => 1, 'blocking_merge_request_id' => 3]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/merge_requests/2/blocks/3') + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->createDependency(1, 2, 3)); + } + + #[Test] + public function shouldGetDependencies(): void + { + $expectedArray = [ + ['id' => 1, 'blocking_merge_request_id' => 3], + ['id' => 2, 'blocking_merge_request_id' => 4], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests/2/blocks') + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->dependencies(1, 2)); + } + + #[Test] + public function shouldDeleteDependency(): void + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/merge_requests/2/blocks/3') + ->willReturn($expectedBool); + + $this->assertEquals($expectedBool, $api->deleteDependency(1, 2, 3)); + } + + #[Test] + public function shouldGetBlockedMergeRequests(): void + { + $expectedArray = [ + ['id' => 3, 'project_id' => 1, 'blocking_merge_request' => [], 'blocked_merge_request' => []], + ['id' => 4, 'project_id' => 1, 'blocking_merge_request' => [], 'blocked_merge_request' => []], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests/2/blockees') + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->blockedMrs(1, 2)); + } }