Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/VCS/Adapter/Git/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ public function listBranches(string $owner, string $repositoryName): array
for ($currentPage = 1; $currentPage <= $maxPages; $currentPage++) {
$url = "/repos/{$owner}/{$repositoryName}/branches?page={$currentPage}&limit={$perPage}";

$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "token $this->accessToken"]);
// We decode ourselves later, because there is edge-case when Gitea returns empty body instead of empty array
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "token $this->accessToken"], decode: false);

$responseHeaders = $response['headers'] ?? [];
$responseHeadersStatusCode = $responseHeaders['status-code'] ?? 0;
Expand All @@ -740,7 +741,7 @@ public function listBranches(string $owner, string $repositoryName): array
break;
}

$responseBody = $response['body'] ?? [];
$responseBody = \json_decode($response['body'] ?? '', true) ?? [];

if (!is_array($responseBody)) {
break;
Expand Down
15 changes: 15 additions & 0 deletions tests/VCS/Adapter/GiteaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,21 @@ public function testListBranches(): void
}
}

public function testListBranchesEmptyRepo(): void
{
$repositoryName = 'test-list-branches-empty-' . \uniqid();
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);

try {
$branches = $this->vcsAdapter->listBranches(static::$owner, $repositoryName);

$this->assertIsArray($branches);
$this->assertEmpty($branches);
} finally {
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
}
}

public function testCreateTag(): void
{
$repositoryName = 'test-create-tag-' . \uniqid();
Expand Down
Loading