Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 25 additions & 3 deletions src/VCS/Adapter/Git/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,24 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri

public function getRepository(string $owner, string $repositoryName): array
{
throw new Exception("Not implemented yet");
$url = "/repos/{$owner}/{$repositoryName}";

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

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

public function getRepositoryName(string $repositoryId): string
{
throw new Exception("Not implemented yet");
$url = "/repositories/{$repositoryId}";

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

Comment thread
Meldiron marked this conversation as resolved.
if (empty($response['body']['name'])) {
Comment thread
Meldiron marked this conversation as resolved.
Outdated
throw new Exception("Repository not found.");
}

return $response['body']['name'];
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

public function getRepositoryTree(string $owner, string $repositoryName, string $branch, bool $recursive = false): array
Expand All @@ -149,7 +161,17 @@ public function listRepositoryContents(string $owner, string $repositoryName, st

public function deleteRepository(string $owner, string $repositoryName): bool
{
throw new Exception("Not implemented yet");
$url = "/repos/{$owner}/{$repositoryName}";

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

$statusCode = $response['headers']['status-code'];

if ($statusCode >= 400) {
throw new Exception("Deleting repository {$repositoryName} failed with status code {$statusCode}");
}

return true;
}

public function createComment(string $owner, string $repositoryName, int $pullRequestNumber, string $comment): string
Expand Down
30 changes: 28 additions & 2 deletions tests/VCS/Adapter/GiteaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,37 @@ public function testCreateRepository(): void
$this->assertSame($repositoryName, $result['name']);
$this->assertArrayHasKey('owner', $result);
$this->assertSame($owner, $result['owner']['login']);
$this->assertTrue($this->vcsAdapter->deleteRepository(self::$owner, $repositoryName));
Comment thread
jaysomani marked this conversation as resolved.
Comment thread
jaysomani marked this conversation as resolved.
}

public function testGetComment(): void
{
$this->markTestSkipped('Will be implemented in follow-up PR');
}

public function testGetRepository(): void
{
$repositoryName = 'test-repo-' . time();
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
Comment thread
jaysomani marked this conversation as resolved.
Outdated
Comment thread
jaysomani marked this conversation as resolved.
Comment thread
jaysomani marked this conversation as resolved.

$result = $this->vcsAdapter->getRepository(self::$owner, $repositoryName);

$this->assertIsArray($result);
$this->assertSame($repositoryName, $result['name']);
$this->assertSame(self::$owner, $result['owner']['login']);
$this->assertTrue($this->vcsAdapter->deleteRepository(self::$owner, $repositoryName));
Comment thread
jaysomani marked this conversation as resolved.
}

public function testGetRepositoryName(): void
{
$this->markTestSkipped('Will be implemented in follow-up PR');
$repositoryName = 'test-repo-' . time();
$created = $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
Comment thread
jaysomani marked this conversation as resolved.
Outdated

Comment thread
jaysomani marked this conversation as resolved.
$repositoryId = (string) $created['id'];
$result = $this->vcsAdapter->getRepositoryName($repositoryId);
Comment thread
jaysomani marked this conversation as resolved.

$this->assertSame($repositoryName, $result);
$this->assertTrue($this->vcsAdapter->deleteRepository(self::$owner, $repositoryName));
Comment thread
jaysomani marked this conversation as resolved.
}

public function testGetRepositoryTree(): void
Expand Down Expand Up @@ -139,7 +160,12 @@ public function testSearchRepositories(): void

public function testDeleteRepository(): void
{
$this->markTestSkipped('Will be implemented in follow-up PR');
$repositoryName = 'test-repo-' . time();
Comment thread
jaysomani marked this conversation as resolved.
Outdated
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);

$result = $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
Comment thread
jaysomani marked this conversation as resolved.

$this->assertTrue($result);
Comment thread
Meldiron marked this conversation as resolved.
}

public function testGetOwnerName(): void
Expand Down