Skip to content

Commit

Permalink
Merge pull request #10 from utopia-php/fix-array-null
Browse files Browse the repository at this point in the history
Add array check for listRepoContents when it's Not Found
  • Loading branch information
christyjacob4 authored Nov 8, 2023
2 parents 40449d8 + 01ca4c2 commit f135291
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public function listRepositoryContents(string $owner, string $repositoryName, st

$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]);

if (($response['headers']['status-code'] == 404)) {
return [];
}

return array_map(static function ($item) {
return $item['name'];
}, $response['body']);
Expand Down
7 changes: 7 additions & 0 deletions tests/Detector/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function setUp(): void

public function testLanguageDetection(): void
{
// test for SUCCESS
$languageMap = [
['vermakhushboo', 'basic-js-crud', 'node'],
['appwrite', 'appwrite', 'php'],
Expand All @@ -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);
}
}

0 comments on commit f135291

Please sign in to comment.