Skip to content

Commit ec25d52

Browse files
committed
Implement getInstallationRepository method
1 parent 0580493 commit ec25d52

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/VCS/Adapter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ abstract public function getOwnerName(string $installationId): string;
9797
*/
9898
abstract public function searchRepositories(string $installationId, string $owner, int $page, int $per_page, string $search = ''): array;
9999

100+
/**
101+
* Get repository for the installation
102+
*
103+
* @param string $repositoryName
104+
* @return array<mixed>
105+
*/
106+
abstract public function getInstallationRepository(string $repositoryName): array;
107+
100108
/**
101109
* Get repository
102110
*

src/VCS/Adapter/Git/GitHub.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,27 @@ public function searchRepositories(string $installationId, string $owner, int $p
189189
];
190190
}
191191

192+
public function getInstallationRepository(string $repositoryName): array
193+
{
194+
$url = '/installation/repositories';
195+
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [
196+
'page' => 1,
197+
'per_page' => 100,
198+
]);
199+
200+
if (!isset($response['body']['repositories'])) {
201+
throw new Exception("Repositories list missing in the response.");
202+
}
203+
204+
foreach ($response['body']['repositories'] as $repo) {
205+
if (\strtolower($repo['name']) === \strtolower($repositoryName)) {
206+
return $repo;
207+
}
208+
}
209+
210+
throw new RepositoryNotFound("Repository not found.");
211+
}
212+
192213
/**
193214
* Get GitHub repository
194215
*

src/VCS/Adapter/Git/Gitea.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public function searchRepositories(string $installationId, string $owner, int $p
118118
throw new Exception("Not implemented yet");
119119
}
120120

121+
public function getInstallationRepository(string $repositoryName): array
122+
{
123+
throw new Exception("Not implemented yet");
124+
}
125+
121126
public function getRepository(string $owner, string $repositoryName): array
122127
{
123128
$url = "/repos/{$owner}/{$repositoryName}";

tests/VCS/Adapter/GitHubTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ public function testGetComment(): void
173173
$this->assertNotEmpty($result);
174174
}
175175

176+
public function testGetInstallationRepository(): void
177+
{
178+
$repositoryName = 'basic-js-crud';
179+
$repo = $this->vcsAdapter->getInstallationRepository($repositoryName);
180+
$this->assertIsArray($repo);
181+
$this->assertSame($repositoryName, $repo['name']);
182+
}
183+
184+
public function testGetRepository(): void
185+
{
186+
$owner = 'vermakhushboo';
187+
$repositoryName = 'basic-js-crud';
188+
$repo = $this->vcsAdapter->getRepository($owner, $repositoryName);
189+
$this->assertIsArray($repo);
190+
$this->assertSame($repositoryName, $repo['name']);
191+
}
192+
176193
public function testGetRepositoryName(): void
177194
{
178195
$repositoryName = $this->vcsAdapter->getRepositoryName('432284323');

0 commit comments

Comments
 (0)