From fb0da7d48cb19d919ece3f32321e325068f47686 Mon Sep 17 00:00:00 2001 From: mborne Date: Wed, 30 Apr 2025 12:34:28 +0200 Subject: [PATCH] feat(archived): add isArchived method (refs #30) --- src/Github/GithubProject.php | 5 +++++ src/Gitlab/GitlabProject.php | 5 +++++ src/Gogs/GogsProject.php | 5 +++++ src/Local/LocalProject.php | 5 +++++ src/ProjectInterface.php | 7 +++++++ tests/GithubClientTest.php | 7 +++++++ tests/GitlabClientTest.php | 12 +++++++++++- tests/GogsClientTest.php | 5 +++++ tests/LocalClientTest.php | 11 +++++++++++ 9 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/Github/GithubProject.php b/src/Github/GithubProject.php index 94350bc..506cc8d 100644 --- a/src/Github/GithubProject.php +++ b/src/Github/GithubProject.php @@ -33,6 +33,11 @@ public function getDefaultBranch(): ?string return $this->rawMetadata['default_branch']; } + public function isArchived(): bool + { + return $this->rawMetadata['archived']; + } + public function getHttpUrl(): string { return $this->rawMetadata['clone_url']; diff --git a/src/Gitlab/GitlabProject.php b/src/Gitlab/GitlabProject.php index 0b9eece..3996649 100644 --- a/src/Gitlab/GitlabProject.php +++ b/src/Gitlab/GitlabProject.php @@ -42,6 +42,11 @@ public function getHttpUrl(): string return $this->rawMetadata['http_url_to_repo']; } + public function isArchived(): bool + { + return $this->rawMetadata['archived']; + } + public function getRawMetadata(): array { return $this->rawMetadata; diff --git a/src/Gogs/GogsProject.php b/src/Gogs/GogsProject.php index 6a5626d..52e9562 100644 --- a/src/Gogs/GogsProject.php +++ b/src/Gogs/GogsProject.php @@ -38,6 +38,11 @@ public function getHttpUrl(): string return $this->rawMetadata['clone_url']; } + public function isArchived(): bool + { + return $this->rawMetadata['archived']; + } + public function getRawMetadata(): array { return $this->rawMetadata; diff --git a/src/Local/LocalProject.php b/src/Local/LocalProject.php index 29574eb..5f20aad 100644 --- a/src/Local/LocalProject.php +++ b/src/Local/LocalProject.php @@ -36,6 +36,11 @@ public function getHttpUrl(): string return $this->rawMetadata['full_path']; } + public function isArchived(): bool + { + return false; // Always returns false for LocalClient + } + public function getRawMetadata(): array { return $this->rawMetadata; diff --git a/src/ProjectInterface.php b/src/ProjectInterface.php index 11f9181..88e9f15 100644 --- a/src/ProjectInterface.php +++ b/src/ProjectInterface.php @@ -29,6 +29,13 @@ public function getDefaultBranch(): ?string; */ public function getHttpUrl(): string; + /** + * True if the project is archived. + * + * @warning This method will always return false for LocalClient. + */ + public function isArchived(): bool; + /** * Get hosting service specific properties. * diff --git a/tests/GithubClientTest.php b/tests/GithubClientTest.php index a018a8f..9b2f31e 100644 --- a/tests/GithubClientTest.php +++ b/tests/GithubClientTest.php @@ -70,7 +70,11 @@ public function testUserAndOrgsRepositories(): void $project = $projectsByName['mborne/satis-gitlab']; $defaultBranch = $project->getDefaultBranch(); + + /* test getDefaultBranch */ $this->assertNotNull($defaultBranch); + + /* test getRawFile */ $composer = $client->getRawFile( $project, 'composer.json', @@ -88,6 +92,9 @@ public function testUserAndOrgsRepositories(): void /* test getRawFile not found */ $this->ensureThatRawFileNotFoundThrowsException($client, $project); + + /* test isArchived */ + $this->assertFalse($project->isArchived()); } /** diff --git a/tests/GitlabClientTest.php b/tests/GitlabClientTest.php index 4ff75bc..99c2496 100644 --- a/tests/GitlabClientTest.php +++ b/tests/GitlabClientTest.php @@ -62,14 +62,18 @@ public function testGitlabDotComByUser(): void ); $project = $projectsByName['mborne/sample-composer']; + /* test getDefaultBranch */ $defaultBranch = $project->getDefaultBranch(); $this->assertNotNull($defaultBranch); + /* test getRawFile */ $composer = $client->getRawFile( $project, 'composer.json', $defaultBranch ); $this->assertStringContainsString('mborne@users.noreply.github.com', $composer); + /* test isArchived */ + $this->assertFalse($project->isArchived()); } public function testGitlabDotComOrgs(): void @@ -117,10 +121,13 @@ public function testGitlabDotComSearch(): void $projectsByName ); - /* test getRawFile */ $project = $projectsByName['mborne/sample-composer']; + + /* test getDefaultBranch */ $defaultBranch = $project->getDefaultBranch(); $this->assertNotNull($defaultBranch); + + /* test getRawFile */ $composer = $client->getRawFile( $project, 'composer.json', @@ -130,5 +137,8 @@ public function testGitlabDotComSearch(): void /* test getRawFile not found */ $this->ensureThatRawFileNotFoundThrowsException($client, $project); + + /* test isArchived */ + $this->assertFalse($project->isArchived()); } } diff --git a/tests/GogsClientTest.php b/tests/GogsClientTest.php index 2a82be3..014a2a2 100644 --- a/tests/GogsClientTest.php +++ b/tests/GogsClientTest.php @@ -111,6 +111,8 @@ public function testFindByUserAndOrgs(): void 'docker/docker-php-sury', $projectsByName ); + + /* test getRawFile */ $project = $projectsByName['docker/docker-php-sury']; $this->assertStringContainsString( 'FROM ', @@ -120,5 +122,8 @@ public function testFindByUserAndOrgs(): void 'ServerTokens Prod', $client->getRawFile($project, 'conf/apache-security.conf', 'master') ); + + /* test isArchived */ + $this->assertFalse($project->isArchived()); } } diff --git a/tests/LocalClientTest.php b/tests/LocalClientTest.php index 323c082..fa9dbe0 100644 --- a/tests/LocalClientTest.php +++ b/tests/LocalClientTest.php @@ -88,6 +88,17 @@ public function testFindAll(): void ); } + /** + * Ensure that isArchived returns false. + */ + public function testIsArchived(): void + { + $projects = $this->findAllProjects(); + foreach ($projects as $project) { + $this->assertFalse($project->isArchived()); + } + } + /** * Check that raw file content can be retreived from non bare repository. */