Skip to content
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:-utopia@example.com}
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:-utopia@example.com}
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:-utopia@example.com}
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 @@ -869,7 +869,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
29 changes: 12 additions & 17 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,28 +558,20 @@ public function getUser(string $username): array

public function getOwnerName(string $installationId, ?int $repositoryId = null): string
{
if ($repositoryId !== null) {
$url = "/projects/{$repositoryId}";
$response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]);
$responseHeaders = $response['headers'] ?? [];
$statusCode = $responseHeaders['status-code'] ?? 0;
if ($statusCode >= 400) {
throw new Exception("Failed to get owner name for repository {$repositoryId}: HTTP {$statusCode}");
}
$responseBody = $response['body'] ?? [];
$namespace = $responseBody['namespace'] ?? [];
return $namespace['path'] ?? '';
if ($repositoryId === null || $repositoryId <= 0) {
throw new Exception("repositoryId is required for this adapter");
}
Comment on lines +561 to 563
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.

P2 Silent breaking change: removal of the /user fallback in getOwnerName

The previous implementation fell back to GET /user when $repositoryId was null, allowing callers to resolve the current authenticated user's namespace without a repository ID. That code path is now replaced with an unconditional exception. Any existing call site that relied on getOwnerName($installationId) without a $repositoryId will fail at runtime with no compile-time warning. The change is intentional based on the test removal, but there is no deprecation notice or migration path in the PR description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is intentional. The previous fallback to GET /user was returning the authenticated username rather than the repository owner/namespace — semantically incorrect behavior. All internal call sites within Appwrite pass a repositoryId. External callers relying on the old fallback should update to pass a valid repositoryId. The PR description has been updated to document this breaking change.

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.

I am not sure if we go ahead with this, notice how we use it in Appwrite:

Image

In many plaes we dont pass repository ID, and I think that would make entire implementation crumble.


$url = "/user";
$url = "/projects/{$repositoryId}";
$response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]);
$responseHeaders = $response['headers'] ?? [];
$statusCode = $responseHeaders['status-code'] ?? 0;
if ($statusCode >= 400) {
throw new Exception("Failed to get current user: HTTP {$statusCode}");
throw new Exception("Failed to get owner name for repository {$repositoryId}: HTTP {$statusCode}");
}
$responseBody = $response['body'] ?? [];
return $responseBody['username'] ?? '';
$namespace = $responseBody['namespace'] ?? [];
return $namespace['path'] ?? '';
}

public function getPullRequest(string $owner, string $repositoryName, int $pullRequestNumber): array
Expand Down
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