Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list repos for GitHub App #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions composer.lock

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

9 changes: 9 additions & 0 deletions src/VCS/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ abstract public function updateCommitStatus(string $repositoryName, string $SHA,
*/
abstract public function getRepositoryTree(string $owner, string $repositoryName, string $branch, bool $recursive = false): array;

/**
* List repositories accessible to the GitHub app
*
* @param int $page page number
* @param int $per_page number of results per page
* @return array<mixed> List of repositories
*/
abstract public function listRepositoriesForGitHubApp(int $page, int $per_page): array;

/**
* Get repository languages
*
Expand Down
23 changes: 23 additions & 0 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ public function getRepositoryTree(string $owner, string $repositoryName, string
return array_column($response['body']['tree'], 'path');
}

/**
* List repositories accessible to the GitHub app
*
* @param int $page page number
* @param int $per_page number of results per page
* @return array<mixed> List of repositories
*/
public function listRepositoriesForGitHubApp(int $page, int $per_page): array
{
$url = '/installation/repositories';

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

if (!isset($response['body']['repositories'])) {
throw new Exception("Repositories list missing in the response.");
}

return $response['body']['repositories'];
}

/**
* Get repository languages
*
Expand Down
7 changes: 7 additions & 0 deletions tests/VCS/Adapter/GitHubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ public function testGetRepositoryTree(): void
$this->assertEquals(1, count($tree));
}

public function testListRepositoriesForGitHubApp(): void
{
$repositories = $this->vcsAdapter->listRepositoriesForGitHubApp(1, 10);
$this->assertIsArray($repositories);
$this->assertCount(4, $repositories);
}

public function testListRepositoryContents(): void
{
$owner = 'test-kh';
Expand Down
Loading