From 9c6d1c3ac86b55fb7b8cd613f3055873714918ba Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 2 Nov 2023 14:11:53 +0000 Subject: [PATCH 1/2] Add array check for listRepoContents --- composer.lock | 28 ++++++++++++++-------------- src/VCS/Adapter/Git/GitHub.php | 4 ++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/composer.lock b/composer.lock index 64052899..ef3fd7bd 100644 --- a/composer.lock +++ b/composer.lock @@ -582,16 +582,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.27", + "version": "9.2.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", "shasum": "" }, "require": { @@ -648,7 +648,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" }, "funding": [ { @@ -656,7 +656,7 @@ "type": "github" } ], - "time": "2023-07-26T13:44:30+00:00" + "time": "2023-09-19T04:57:46+00:00" }, { "name": "phpunit/php-file-iterator", @@ -901,16 +901,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.11", + "version": "9.6.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "810500e92855eba8a7a5319ae913be2da6f957b0" + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/810500e92855eba8a7a5319ae913be2da6f957b0", - "reference": "810500e92855eba8a7a5319ae913be2da6f957b0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", "shasum": "" }, "require": { @@ -925,7 +925,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-code-coverage": "^9.2.28", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -984,7 +984,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.11" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" }, "funding": [ { @@ -1000,7 +1000,7 @@ "type": "tidelift" } ], - "time": "2023-08-19T07:10:56+00:00" + "time": "2023-09-19T05:39:22+00:00" }, { "name": "sebastian/cli-parser", @@ -2026,5 +2026,5 @@ "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 53f9e173..7e58238b 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -187,6 +187,10 @@ public function listRepositoryContents(string $owner, string $repositoryName, st $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]); + if (!is_array($response['body'])) { + return []; + } + return array_map(static function ($item) { return $item['name']; }, $response['body']); From 01ca4c268f6fda903c750bf03f131d4d24b228f1 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:46:48 +0530 Subject: [PATCH 2/2] Fix code and add correspondingtest --- src/VCS/Adapter/Git/GitHub.php | 2 +- tests/Detector/DetectorTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 7e58238b..a6d25a18 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -187,7 +187,7 @@ public function listRepositoryContents(string $owner, string $repositoryName, st $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]); - if (!is_array($response['body'])) { + if (($response['headers']['status-code'] == 404)) { return []; } diff --git a/tests/Detector/DetectorTest.php b/tests/Detector/DetectorTest.php index 3174d768..2f0a4c13 100644 --- a/tests/Detector/DetectorTest.php +++ b/tests/Detector/DetectorTest.php @@ -61,6 +61,7 @@ public function setUp(): void public function testLanguageDetection(): void { + // test for SUCCESS $languageMap = [ ['vermakhushboo', 'basic-js-crud', 'node'], ['appwrite', 'appwrite', 'php'], @@ -82,5 +83,11 @@ public function testLanguageDetection(): void $runtime = $this->detect($files, $languages); $this->assertEquals($expectedRuntime, $runtime); } + + // test for FAILURE + $files = $this->github->listRepositoryContents('', ''); + $languages = $this->github->listRepositoryLanguages('', ''); + $runtime = $this->detect($files, $languages); + $this->assertEquals(null, $runtime); } }