Skip to content

Commit 0eea94d

Browse files
committed
Support merge request dependency endpoint
1 parent 1bf5326 commit 0eea94d

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/Api/MergeRequests.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,26 @@ public function deleteLevelRule(int|string $project_id, int $mr_iid, int $approv
368368
{
369369
return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/approval_rules/'.self::encodePath($approval_rule_id)));
370370
}
371+
372+
public function createDependency(int|string $project_id, int $mr_iid, int $blocking_merge_request_id): mixed
373+
{
374+
return $this->post($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blocks'), [
375+
'blocking_merge_request_id' => $blocking_merge_request_id,
376+
]);
377+
}
378+
379+
public function dependencies(int|string $project_id, int $mr_iid): mixed
380+
{
381+
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blocks'));
382+
}
383+
384+
public function deleteDependency(int|string $project_id, int $mr_iid, int $block_id): mixed
385+
{
386+
return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blocks/'.self::encodePath($block_id)));
387+
}
388+
389+
public function blockedMrs(int|string $project_id, int $mr_iid): mixed
390+
{
391+
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/blockees'));
392+
}
371393
}

tests/Api/MergeRequestsTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,4 +822,69 @@ public function shouldRebaseMergeRequest(): void
822822
'skip_ci' => true,
823823
]));
824824
}
825+
826+
#[Test]
827+
public function shouldCreateDependency(): void
828+
{
829+
$expectedArray = ['id' => 1, 'blocking_merge_request_id' => 3];
830+
831+
$api = $this->getApiMock();
832+
$api->expects($this->once())
833+
->method('post')
834+
->with('projects/1/merge_requests/2/blocks/3')
835+
->willReturn($expectedArray)
836+
;
837+
838+
$this->assertEquals($expectedArray, $api->createDependency(1, 2, 3));
839+
}
840+
841+
#[Test]
842+
public function shouldGetDependencies(): void
843+
{
844+
$expectedArray = [
845+
['id' => 1, 'blocking_merge_request_id' => 3],
846+
['id' => 2, 'blocking_merge_request_id' => 4],
847+
];
848+
849+
$api = $this->getApiMock();
850+
$api->expects($this->once())
851+
->method('get')
852+
->with('projects/1/merge_requests/2/blocks')
853+
->willReturn($expectedArray)
854+
;
855+
856+
$this->assertEquals($expectedArray, $api->dependencies(1, 2));
857+
}
858+
859+
#[Test]
860+
public function shouldDeleteDependency(): void
861+
{
862+
$expectedBool = true;
863+
864+
$api = $this->getApiMock();
865+
$api->expects($this->once())
866+
->method('delete')
867+
->with('projects/1/merge_requests/2/blocks/3')
868+
->willReturn($expectedBool);
869+
870+
$this->assertEquals($expectedBool, $api->deleteDependency(1, 2, 3));
871+
}
872+
873+
#[Test]
874+
public function shouldGetBlockedMergeRequests(): void
875+
{
876+
$expectedArray = [
877+
['id' => 3, 'project_id' => 1, 'blocking_merge_request' => [], 'blocked_merge_request' => []],
878+
['id' => 4, 'project_id' => 1, 'blocking_merge_request' => [], 'blocked_merge_request' => []],
879+
];
880+
881+
$api = $this->getApiMock();
882+
$api->expects($this->once())
883+
->method('get')
884+
->with('projects/1/merge_requests/2/blockees')
885+
->willReturn($expectedArray)
886+
;
887+
888+
$this->assertEquals($expectedArray, $api->blockedMrs(1, 2));
889+
}
825890
}

0 commit comments

Comments
 (0)