Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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:-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 thread
greptile-apps[bot] marked this conversation as resolved.
Outdated

$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