diff --git a/composer.lock b/composer.lock index 8f21fda..2ada838 100644 --- a/composer.lock +++ b/composer.lock @@ -65,16 +65,16 @@ }, { "name": "utopia-php/cache", - "version": "0.10.0", + "version": "0.10.2", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "313bcdfbb166f75c2c205a59d1467cead63a9626" + "reference": "b22c6eb6d308de246b023efd0fc9758aee8b8247" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/313bcdfbb166f75c2c205a59d1467cead63a9626", - "reference": "313bcdfbb166f75c2c205a59d1467cead63a9626", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/b22c6eb6d308de246b023efd0fc9758aee8b8247", + "reference": "b22c6eb6d308de246b023efd0fc9758aee8b8247", "shasum": "" }, "require": { @@ -109,9 +109,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.10.0" + "source": "https://github.com/utopia-php/cache/tree/0.10.2" }, - "time": "2024-06-05T16:40:43+00:00" + "time": "2024-06-25T20:36:35+00:00" }, { "name": "utopia-php/framework", @@ -301,16 +301,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.1", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", "shasum": "" }, "require": { @@ -318,11 +318,12 @@ }, "conflict": { "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3,<3.2.2" + "doctrine/common": "<2.13.3 || >=3 <3.2.2" }, "require-dev": { "doctrine/collections": "^1.6.8", "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", @@ -348,7 +349,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" }, "funding": [ { @@ -356,7 +357,7 @@ "type": "tidelift" } ], - "time": "2023-03-08T13:26:56+00:00" + "time": "2024-06-12T14:39:25+00:00" }, { "name": "nikic/php-parser", @@ -2038,5 +2039,5 @@ "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 7de9650..53fe1e7 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -16,6 +16,10 @@ class GitHub extends Git public const EVENT_INSTALLATION = 'installation'; + public const CONTENTS_DIRECTORY = 'dir'; + + public const CONTENTS_FILE = 'file'; + protected string $endpoint = 'https://api.github.com'; protected string $accessToken; @@ -213,15 +217,25 @@ public function listRepositoryContents(string $owner, string $repositoryName, st return []; } - if (isset($response['body'][0])) { - return array_column($response['body'], 'name'); + $items = []; + + if (!empty($response['body'][0])) { + $items = $response['body']; + } elseif (!empty($response['body'])) { + $items = [$response['body']]; } - if (isset($response['body']['name'])) { - return [$response['body']['name']]; + $contents = []; + foreach ($items as $item) { + $type = $item['type'] ?? 'file'; + $contents[] = [ + 'name' => $item['name'] ?? '', + 'size' => $item['size'] ?? 0, + 'type' => $type === 'file' ? self::CONTENTS_FILE : self::CONTENTS_DIRECTORY + ]; } - return []; + return $contents; } public function deleteRepository(string $owner, string $repositoryName): bool diff --git a/tests/Detector/DetectorTest.php b/tests/Detector/DetectorTest.php index c151d5d..2ac4826 100644 --- a/tests/Detector/DetectorTest.php +++ b/tests/Detector/DetectorTest.php @@ -79,6 +79,7 @@ public function testLanguageDetection(): void foreach ($languageMap as [$owner, $repositoryName, $expectedRuntime]) { $files = $this->github->listRepositoryContents($owner, $repositoryName); + $files = \array_column($files, 'name'); $languages = $this->github->listRepositoryLanguages($owner, $repositoryName); $runtime = $this->detect($files, $languages); $this->assertEquals($expectedRuntime, $runtime); @@ -86,6 +87,7 @@ public function testLanguageDetection(): void // test for FAILURE $files = $this->github->listRepositoryContents('', ''); + $files = \array_column($files, 'name'); $languages = $this->github->listRepositoryLanguages('', ''); $runtime = $this->detect($files, $languages); $this->assertEquals(null, $runtime); diff --git a/tests/VCS/Base.php b/tests/VCS/Base.php index 5ca7708..b87413b 100644 --- a/tests/VCS/Base.php +++ b/tests/VCS/Base.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Utopia\Http\Http; use Utopia\VCS\Adapter\Git; +use Utopia\VCS\Adapter\Git\GitHub; abstract class Base extends TestCase { @@ -83,6 +84,37 @@ public function testListRepositoryContents(): void $contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', 'src/Appwrite'); $this->assertIsArray($contents); $this->assertNotEmpty($contents); + + + $contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', ''); + $this->assertIsArray($contents); + $this->assertNotEmpty($contents); + $this->assertGreaterThan(0, \count($contents)); + + $fileContent = null; + foreach ($contents as $content) { + if ($content['type'] === GitHub::CONTENTS_FILE) { + $fileContent = $content; + break; + } + } + $this->assertNotNull($fileContent); + $this->assertNotEmpty($fileContent['name']); + $this->assertStringContainsString('.', $fileContent['name']); + $this->assertIsNumeric($fileContent['size']); + $this->assertGreaterThan(0, $fileContent['size']); + + $directoryContent = null; + foreach ($contents as $content) { + if ($content['type'] === GitHub::CONTENTS_DIRECTORY) { + $directoryContent = $content; + break; + } + } + $this->assertNotNull($directoryContent); + $this->assertNotEmpty($directoryContent['name']); + $this->assertIsNumeric($directoryContent['size']); + $this->assertEquals(0, $directoryContent['size']); } public function testCreateRepository(): void