Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/VCS/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ abstract public function getOwnerName(string $installationId): string;
*/
abstract public function searchRepositories(string $installationId, string $owner, int $page, int $per_page, string $search = ''): array;

/**
* Get repository for the installation
*
* @param string $repositoryName
* @return array<mixed>
*/
abstract public function getInstallationRepository(string $repositoryName): array;

/**
* Get repository
*
Expand Down
21 changes: 21 additions & 0 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ public function searchRepositories(string $installationId, string $owner, int $p
];
}

public function getInstallationRepository(string $repositoryName): array
{
$url = '/installation/repositories';
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [
'page' => 1,
'per_page' => 100,
Comment thread
hmacr marked this conversation as resolved.
Outdated
]);

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

foreach ($response['body']['repositories'] as $repo) {
if (\strtolower($repo['name']) === \strtolower($repositoryName)) {
return $repo;
}
}

throw new RepositoryNotFound("Repository not found.");
Comment thread
hmacr marked this conversation as resolved.
}
Comment thread
hmacr marked this conversation as resolved.

/**
* Get GitHub repository
*
Expand Down
5 changes: 5 additions & 0 deletions src/VCS/Adapter/Git/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public function searchRepositories(string $installationId, string $owner, int $p
throw new Exception("Not implemented yet");
}

public function getInstallationRepository(string $repositoryName): array
{
throw new Exception("Not implemented yet");
}

public function getRepository(string $owner, string $repositoryName): array
{
$url = "/repos/{$owner}/{$repositoryName}";
Expand Down
17 changes: 17 additions & 0 deletions tests/VCS/Adapter/GitHubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ public function testGetComment(): void
$this->assertNotEmpty($result);
}

public function testGetInstallationRepository(): void
{
$repositoryName = 'basic-js-crud';
$repo = $this->vcsAdapter->getInstallationRepository($repositoryName);
$this->assertIsArray($repo);
$this->assertSame($repositoryName, $repo['name']);
}
Comment thread
hmacr marked this conversation as resolved.

public function testGetRepository(): void
{
$owner = 'vermakhushboo';
$repositoryName = 'basic-js-crud';
$repo = $this->vcsAdapter->getRepository($owner, $repositoryName);
$this->assertIsArray($repo);
$this->assertSame($repositoryName, $repo['name']);
}

public function testGetRepositoryName(): void
{
$repositoryName = $this->vcsAdapter->getRepositoryName('432284323');
Expand Down
Loading