Skip to content
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
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ services:
required: false
entrypoint: /bin/sh
environment:
- GITEA_ADMIN_USERNAME=${GITEA_ADMIN_USERNAME:-utopia}
- GITEA_ADMIN_USERNAME=${GITEA_ADMIN_USERNAME:-root}
- GITEA_ADMIN_PASSWORD=${GITEA_ADMIN_PASSWORD:-password}
- GITEA_ADMIN_EMAIL=${GITEA_ADMIN_EMAIL:[email protected]}
command: >
Expand Down Expand Up @@ -137,7 +137,7 @@ services:
required: false
entrypoint: /bin/sh
environment:
- FORGEJO_ADMIN_USERNAME=${FORGEJO_ADMIN_USERNAME:-utopia}
- FORGEJO_ADMIN_USERNAME=${FORGEJO_ADMIN_USERNAME:-root}
- FORGEJO_ADMIN_PASSWORD=${FORGEJO_ADMIN_PASSWORD:-password}
- FORGEJO_ADMIN_EMAIL=${FORGEJO_ADMIN_EMAIL:[email protected]}
command: >
Expand Down Expand Up @@ -178,7 +178,7 @@ services:
required: false
entrypoint: /bin/sh
environment:
- GOGS_ADMIN_USERNAME=${GOGS_ADMIN_USERNAME:-utopia}
- GOGS_ADMIN_USERNAME=${GOGS_ADMIN_USERNAME:-root}
- GOGS_ADMIN_PASSWORD=${GOGS_ADMIN_PASSWORD:-password}
- GOGS_ADMIN_EMAIL=${GOGS_ADMIN_EMAIL:[email protected]}
command:
Expand Down
10 changes: 7 additions & 3 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
$responseBody = $response['body'] ?? [];

if (!array_key_exists('items', $responseBody)) {
throw new Exception("Repositories list missing in the response.");
return ['items' => [], 'total' => 0];
}

return [
Expand All @@ -255,7 +255,7 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
$responseBody = $response['body'] ?? [];

if (!array_key_exists('repositories', $responseBody)) {
throw new Exception("Repositories list missing in the response.");
return ['items' => [], 'total' => 0];
}

return [
Expand Down Expand Up @@ -886,7 +886,11 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s
'context' => $context,
];

$this->call(self::METHOD_POST, $url, ['Authorization' => "Bearer $this->accessToken"], $body);
$response = $this->call(self::METHOD_POST, $url, ['Authorization' => "Bearer $this->accessToken"], $body);
$statusCode = $response['headers']['status-code'] ?? 0;
if ($statusCode >= 400) {
throw new Exception("Failed to update commit status: HTTP {$statusCode}");
}
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/VCS/Adapter/Git/GitLab.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
}

if ($statusCode >= 400) {
return [];
return ['items' => [], 'total' => 0];
}

$responseBody = $response['body'] ?? [];
if (!is_array($responseBody)) {
return [];
return ['items' => [], 'total' => 0];
}

$repositories = [];
Expand All @@ -217,7 +217,10 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
];
}

return $repositories;
return [
'items' => $repositories,
'total' => (int) ($responseHeaders['x-total'] ?? count($repositories)),
];
}

public function getRepositoryName(string $repositoryId): string
Expand Down Expand Up @@ -555,7 +558,7 @@ public function getUser(string $username): array

public function getOwnerName(string $installationId, ?int $repositoryId = null): string
{
if ($repositoryId !== null) {
if ($repositoryId !== null && $repositoryId > 0) {
$url = "/projects/{$repositoryId}";
$response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]);
$responseHeaders = $response['headers'] ?? [];
Expand Down
17 changes: 16 additions & 1 deletion src/VCS/Adapter/Git/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,21 @@ public function getCommitStatuses(string $owner, string $repositoryName, string
throw new Exception("Failed to get commit statuses: HTTP {$responseHeadersStatusCode}", $responseHeadersStatusCode);
}

return $response['body'] ?? [];
$responseBody = $response['body'] ?? [];
if (!is_array($responseBody)) {
return [];
}

$statuses = [];
foreach ($responseBody as $status) {
$statuses[] = [
'state' => $status['status'] ?? '',
'description' => $status['description'] ?? '',
'target_url' => $status['target_url'] ?? '',
'context' => $status['context'] ?? '',
];
}

return $statuses;
}
}
Comment on lines 1155 to 1175

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 getCommitStatuses field rename breaks existing callers

The normalization renames the commit-state field from status (the raw Gitea/Gogs API field) to state. Any caller that was reading $result['status'] from Gitea::getCommitStatuses() — including the now-deleted testUpdateCommitStatus in GiteaTest, which asserted $status['status'] ?? '' — will silently receive null/empty string instead. The PR description only lists GitLab and GitHub adapter fixes; this Gitea change is undocumented and the roundtrip test that would have caught it was removed without a base-level replacement that verifies the state field.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

8 changes: 1 addition & 7 deletions tests/VCS/Adapter/ForgejoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Utopia\Cache\Adapter\None;
use Utopia\Cache\Cache;
use Utopia\System\System;
use Utopia\VCS\Adapter\Git;
use Utopia\VCS\Adapter\Git\Forgejo;

class ForgejoTest extends GiteaTest
Expand All @@ -18,12 +17,7 @@ class ForgejoTest extends GiteaTest
protected string $webhookSignatureHeader = 'X-Forgejo-Signature';
protected string $avatarDomain = 'http://localhost:3000/avatars/';

protected function createVCSAdapter(): Git
{
return new Forgejo(new Cache(new None()));
}

public function setUp(): void
public function setupAdapter(): void
{
if (empty(static::$accessToken)) {
$this->setupForgejo();
Expand Down
Loading
Loading