From 2d0f4b9fbe4caf1ec26d6ee138a473bcefa0d7af Mon Sep 17 00:00:00 2001 From: Wesley Sartori Date: Wed, 20 Aug 2025 00:29:36 -0300 Subject: [PATCH 1/3] feat: Added latest pipeline route --- src/Api/Projects.php | 5 ++++ tests/Api/ProjectsTest.php | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/Api/Projects.php b/src/Api/Projects.php index 32aa168a..fe96293b 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -319,6 +319,11 @@ public function pipeline(int|string $project_id, int $pipeline_id): mixed return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id))); } + public function latestPipeline(int|string $project_id): mixed + { + return $this->get($this->getProjectPath($project_id, 'pipelines/latest')); + } + public function pipelineJobs(int|string $project_id, int $pipeline_id): mixed { return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id).'/jobs')); diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index 62b5dfcc..44b5cb08 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2765,4 +2765,60 @@ public function shouldSearchGroups(): void 'sort' => 'desc', ])); } + + #[Test] + public function shouldLatestPipeline(): void + { + $expectedArray = [ + "id" => 1, + "iid" => 11, + "project_id" => 1, + "sha" => "005b54847000bd171b3fc64fb86d23f17d488456", + "ref" => "branch-name", + "status" => "failed", + "source" => "schedule", + "created_at" => "2025-08-19T17:17:21.946Z", + "updated_at" => "2025-08-19T20:30:54.436Z", + "web_url" => "https://gitlab.domain.com/group/project-1/-/pipelines/2", + "before_sha" => "0000000000000000000000000000000000000000", + "tag" => false, + "yaml_errors" => null, + "user" => [ + "id" => 1, + "username" => "username", + "public_email" => "", + "name" => "Username", + "state" => "active", + "locked" => false, + "avatar_url" => "https://gitlab.domain.com/uploads/-/system/user/avatar/1/avatar.png", + "web_url" => "https://gitlab.domain.com/usernam" + ], + "started_at" => "2025-08-19T17:17:24.643Z", + "finished_at" => "2025-08-19T20:30:54.414Z", + "committed_at" => null, + "duration" => 51, + "queued_duration" => 2, + "coverage" => null, + "detailed_status" => [ + "icon" => "status_failed", + "text" => "Failed", + "label" => "failed", + "group" => "failed", + "tooltip" => "failed", + "has_details" => false, + "details_path" => "/group/project-1/-/pipelines/2", + "illustration" => null, + "favicon" => "/assets/ci_favicons/favicon_status_failed-312312312hghj312j3jh4123hj13j1h2.png" + ], + "name" => null + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/pipelines/latest') + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->latestPipeline(1)); + } } From e1e07c82ec1b7725f3bbabd7b0b5c973e5dd8e9b Mon Sep 17 00:00:00 2001 From: Wesley Sartori Date: Wed, 20 Aug 2025 00:36:24 -0300 Subject: [PATCH 2/3] feat: Added latest pipeline route --- tests/Api/ProjectsTest.php | 79 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index 44b5cb08..b5ce6da9 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2770,47 +2770,47 @@ public function shouldSearchGroups(): void public function shouldLatestPipeline(): void { $expectedArray = [ - "id" => 1, - "iid" => 11, - "project_id" => 1, - "sha" => "005b54847000bd171b3fc64fb86d23f17d488456", - "ref" => "branch-name", - "status" => "failed", - "source" => "schedule", - "created_at" => "2025-08-19T17:17:21.946Z", - "updated_at" => "2025-08-19T20:30:54.436Z", - "web_url" => "https://gitlab.domain.com/group/project-1/-/pipelines/2", - "before_sha" => "0000000000000000000000000000000000000000", - "tag" => false, - "yaml_errors" => null, - "user" => [ - "id" => 1, - "username" => "username", - "public_email" => "", - "name" => "Username", - "state" => "active", - "locked" => false, - "avatar_url" => "https://gitlab.domain.com/uploads/-/system/user/avatar/1/avatar.png", - "web_url" => "https://gitlab.domain.com/usernam" + 'id' => 1, + 'iid' => 11, + 'project_id' => 1, + 'sha' => '005b54847000bd171b3fc64fb86d23f17d488456', + 'ref' => 'branch-name', + 'status' => 'failed', + 'source' => 'schedule', + 'created_at' => '2025-08-19T17:17:21.946Z', + 'updated_at' => '2025-08-19T20:30:54.436Z', + 'web_url' => 'https://gitlab.domain.com/group/project-1/-/pipelines/2', + 'before_sha' => '0000000000000000000000000000000000000000', + 'tag' => false, + 'yaml_errors' => null, + 'user' => [ + 'id' => 1, + 'username' => 'username', + 'public_email' => '', + 'name' => 'Username', + 'state' => 'active', + 'locked' => false, + 'avatar_url' => 'https://gitlab.domain.com/uploads/-/system/user/avatar/1/avatar.png', + 'web_url' => 'https://gitlab.domain.com/usernam' ], - "started_at" => "2025-08-19T17:17:24.643Z", - "finished_at" => "2025-08-19T20:30:54.414Z", - "committed_at" => null, - "duration" => 51, - "queued_duration" => 2, - "coverage" => null, - "detailed_status" => [ - "icon" => "status_failed", - "text" => "Failed", - "label" => "failed", - "group" => "failed", - "tooltip" => "failed", - "has_details" => false, - "details_path" => "/group/project-1/-/pipelines/2", - "illustration" => null, - "favicon" => "/assets/ci_favicons/favicon_status_failed-312312312hghj312j3jh4123hj13j1h2.png" + 'started_at' => '2025-08-19T17:17:24.643Z', + 'finished_at' => '2025-08-19T20:30:54.414Z', + 'committed_at' => null, + 'duration' => 51, + 'queued_duration' => 2, + 'coverage' => null, + 'detailed_status' => [ + 'icon' => 'status_failed', + 'text' => 'Failed', + 'label' => 'failed', + 'group' => 'failed', + 'tooltip' => 'failed', + 'has_details' => false, + 'details_path' => '/group/project-1/-/pipelines/2', + 'illustration' => null, + 'favicon' => '/assets/ci_favicons/favicon_status_failed-312312312hghj312j3jh4123hj13j1h2.png' ], - "name" => null + 'name' => null ]; $api = $this->getApiMock(); @@ -2818,7 +2818,6 @@ public function shouldLatestPipeline(): void ->method('get') ->with('projects/1/pipelines/latest') ->willReturn($expectedArray); - $this->assertEquals($expectedArray, $api->latestPipeline(1)); } } From 5781ec78a867713ea6bf5865d1f324d0cb3f831b Mon Sep 17 00:00:00 2001 From: Wesley Sartori Date: Wed, 20 Aug 2025 00:37:18 -0300 Subject: [PATCH 3/3] feat: Added latest pipeline route --- tests/Api/ProjectsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index b5ce6da9..cbfc7e27 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2791,7 +2791,7 @@ public function shouldLatestPipeline(): void 'state' => 'active', 'locked' => false, 'avatar_url' => 'https://gitlab.domain.com/uploads/-/system/user/avatar/1/avatar.png', - 'web_url' => 'https://gitlab.domain.com/usernam' + 'web_url' => 'https://gitlab.domain.com/usernam', ], 'started_at' => '2025-08-19T17:17:24.643Z', 'finished_at' => '2025-08-19T20:30:54.414Z', @@ -2808,9 +2808,9 @@ public function shouldLatestPipeline(): void 'has_details' => false, 'details_path' => '/group/project-1/-/pipelines/2', 'illustration' => null, - 'favicon' => '/assets/ci_favicons/favicon_status_failed-312312312hghj312j3jh4123hj13j1h2.png' + 'favicon' => '/assets/ci_favicons/favicon_status_failed-312312312hghj312j3jh4123hj13j1h2.png', ], - 'name' => null + 'name' => null, ]; $api = $this->getApiMock();