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..e5940201 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)); + } }