From 598f5d2507ea2950678353098e018d03136e23fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20W=C3=B3jcik?= Date: Sun, 21 Apr 2024 21:58:17 +0200 Subject: [PATCH 1/5] Implement merge request resource label API methods --- src/Api/MergeRequests.php | 33 ++++++++++++ tests/Api/MergeRequestsTest.php | 95 +++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 2bb8584a..4bf44491 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -578,4 +578,37 @@ public function deleteLevelRule($project_id, int $mr_iid, int $approval_rule_id) { return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/approval_rules/'.self::encodePath($approval_rule_id))); } + + /** + * @param int|string $project_id + * @param int $mr_iid + * + * @return mixed + */ + public function resourceLabelEvents($project_id, int $mr_iid) + { + return $this->get( + $this->getProjectPath( + $project_id, + 'merge_requests/'.self::encodePath($mr_iid).'/resource_label_events' + ) + ); + } + + /** + * @param int|string $project_id + * @param int $mr_iid + * @param int $resource_label_event_id + * + * @return mixed + */ + public function resourceLabelEvent($project_id, int $mr_iid, int $resource_label_event_id) + { + return $this->get( + $this->getProjectPath( + $project_id, + 'merge_requests/'.self::encodePath($mr_iid).'/resource_label_events/'.self::encodePath($resource_label_event_id) + ) + ); + } } diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index 227b89a0..0b250456 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -904,4 +904,99 @@ public function shouldRebaseMergeRequest(): void 'skip_ci' => true, ])); } + + /** + * @test + */ + public function shouldGetResourceLabelEvents(): void + { + $expectedArray = [ + [ + 'id' => 119, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http://gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T06:17:28.394Z', + 'resource_type' => 'MergeRequest', + 'resource_id' => 28, + 'label' => [ + 'id' => 74, + 'name' => 'p1', + 'color' => "#0033CC", + 'description' => '' + ], + 'action' => 'add' + ], + [ + 'id' => 120, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http://gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T06:17:28.394Z', + 'resource_type' => 'MergeRequest', + 'resource_id' => 28, + 'label' => [ + 'id' => 41, + 'name' => 'project', + 'color' => "#D1D100", + 'description' => '' + ], + 'action' => 'add' + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests/2/resource_label_events') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->resourceLabelEvents(1, 2)); + } + + /** + * @test + */ + public function shouldGetResourceLabelEventById(): void + { + $expectedArray = [ + 'id' => 119, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http://gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T06:17:28.394Z', + 'resource_type' => 'MergeRequest', + 'resource_id' => 28, + 'label' => [ + 'id' => 74, + 'name' => 'p1', + 'color' => "#0033CC", + 'description' => '' + ], + 'action' => 'add' + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests/2/resource_label_events/3') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->resourceLabelEvent(1, 2, 3)); + } } From ca6fd6bcfa871a432a7be52f3f2c399f8df5104e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20W=C3=B3jcik?= Date: Sun, 21 Apr 2024 22:07:14 +0200 Subject: [PATCH 2/5] fix style --- tests/Api/MergeRequestsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index 0b250456..4ad95821 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -927,8 +927,8 @@ public function shouldGetResourceLabelEvents(): void 'label' => [ 'id' => 74, 'name' => 'p1', - 'color' => "#0033CC", - 'description' => '' + 'color' => '#0033CC', + 'description' => '', ], 'action' => 'add' ], @@ -948,8 +948,8 @@ public function shouldGetResourceLabelEvents(): void 'label' => [ 'id' => 41, 'name' => 'project', - 'color' => "#D1D100", - 'description' => '' + 'color' => '#D1D100', + 'description' => '', ], 'action' => 'add' ], From 0cc5a0a381f4d4543a13740eb5884bf2c55aedc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20W=C3=B3jcik?= Date: Sun, 21 Apr 2024 22:07:20 +0200 Subject: [PATCH 3/5] fix style --- src/Api/MergeRequests.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 4bf44491..f82df1df 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -583,7 +583,7 @@ public function deleteLevelRule($project_id, int $mr_iid, int $approval_rule_id) * @param int|string $project_id * @param int $mr_iid * - * @return mixed + * @return array */ public function resourceLabelEvents($project_id, int $mr_iid) { @@ -600,7 +600,7 @@ public function resourceLabelEvents($project_id, int $mr_iid) * @param int $mr_iid * @param int $resource_label_event_id * - * @return mixed + * @return array */ public function resourceLabelEvent($project_id, int $mr_iid, int $resource_label_event_id) { From 5c9d3fd22ba28a88dd492f2b17227849a13ade9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20W=C3=B3jcik?= Date: Sun, 21 Apr 2024 22:08:46 +0200 Subject: [PATCH 4/5] fix style --- tests/Api/MergeRequestsTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index 4ad95821..e5940201 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -930,7 +930,7 @@ public function shouldGetResourceLabelEvents(): void 'color' => '#0033CC', 'description' => '', ], - 'action' => 'add' + 'action' => 'add', ], [ 'id' => 120, @@ -951,7 +951,7 @@ public function shouldGetResourceLabelEvents(): void 'color' => '#D1D100', 'description' => '', ], - 'action' => 'add' + 'action' => 'add', ], ]; @@ -985,10 +985,10 @@ public function shouldGetResourceLabelEventById(): void 'label' => [ 'id' => 74, 'name' => 'p1', - 'color' => "#0033CC", - 'description' => '' + 'color' => '#0033CC', + 'description' => '', ], - 'action' => 'add' + 'action' => 'add', ]; $api = $this->getApiMock(); From 39e2a2449682122ef40cb25d01f6b89fde0839d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20W=C3=B3jcik?= Date: Wed, 24 Apr 2024 21:24:50 +0200 Subject: [PATCH 5/5] phpstan issue fix --- src/Api/MergeRequests.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index f82df1df..4bf44491 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -583,7 +583,7 @@ public function deleteLevelRule($project_id, int $mr_iid, int $approval_rule_id) * @param int|string $project_id * @param int $mr_iid * - * @return array + * @return mixed */ public function resourceLabelEvents($project_id, int $mr_iid) { @@ -600,7 +600,7 @@ public function resourceLabelEvents($project_id, int $mr_iid) * @param int $mr_iid * @param int $resource_label_event_id * - * @return array + * @return mixed */ public function resourceLabelEvent($project_id, int $mr_iid, int $resource_label_event_id) {