Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
48 changes: 47 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ services:
- ./phpunit.xml:/usr/local/src/phpunit.xml
- gitea-data:/data:ro
- forgejo-data:/forgejo-data:ro
- gogs-data:/gogs-data:ro
environment:
- TESTS_GITHUB_PRIVATE_KEY
- TESTS_GITHUB_APP_IDENTIFIER
- TESTS_GITHUB_INSTALLATION_ID
- TESTS_GITEA_URL=http://gitea:3000
- TESTS_GITEA_REQUEST_CATCHER_URL=http://request-catcher:5000
- TESTS_FORGEJO_URL=http://forgejo:3000
- TESTS_GOGS_URL=http://gogs:3000
depends_on:
gitea:
condition: service_healthy
Expand All @@ -24,6 +26,10 @@ services:
condition: service_healthy
forgejo-bootstrap:
condition: service_completed_successfully
gogs:
condition: service_healthy
gogs-bootstrap:
condition: service_completed_successfully
request-catcher:
condition: service_started

Expand Down Expand Up @@ -115,6 +121,46 @@ services:
fi
"

gogs:
image: gogs/gogs:0.13
environment:
- GOGS_CUSTOM=/data/gogs
volumes:
- gogs-data:/data
- ./tests/resources/gogs-custom/conf/app.ini:/data/gogs/conf/app.ini
ports:
- "3002:3000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
interval: 10s
timeout: 5s
retries: 10
start_period: 15s

gogs-bootstrap:
image: gogs/gogs:0.13
volumes:
- gogs-data:/data
depends_on:
gogs:
condition: service_healthy
entrypoint: /bin/sh
environment:
- GOGS_ADMIN_USERNAME=${GOGS_ADMIN_USERNAME:-utopia}
- GOGS_ADMIN_PASSWORD=${GOGS_ADMIN_PASSWORD:-password}
- GOGS_ADMIN_EMAIL=${GOGS_ADMIN_EMAIL:-utopia@example.com}
command: >
-c "
su git -c \"/opt/gogs/gogs admin create-user --name=$$GOGS_ADMIN_USERNAME --password=$$GOGS_ADMIN_PASSWORD --email=$$GOGS_ADMIN_EMAIL --admin\" || true &&
if [ ! -f /data/gogs/token.txt ]; then
Comment thread
Meldiron marked this conversation as resolved.
Outdated
apk add --no-cache curl jq &&
TOKEN=$$(curl -s -X POST http://gogs:3000/api/v1/users/$$GOGS_ADMIN_USERNAME/tokens -H 'Content-Type: application/json' -d '{\"name\":\"bootstrap-token\"}' -u $$GOGS_ADMIN_USERNAME:$$GOGS_ADMIN_PASSWORD | jq -r '.sha1') &&
mkdir -p /data/gogs &&
echo $$TOKEN > /data/gogs/token.txt;
fi
"

volumes:
gitea-data:
forgejo-data:
forgejo-data:
gogs-data:
48 changes: 48 additions & 0 deletions src/VCS/Adapter/Git/Gogs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Utopia\VCS\Adapter\Git;

class Gogs extends Gitea
{
protected string $endpoint = 'http://gogs:3000/api/v1';
Comment thread
Meldiron marked this conversation as resolved.

/**
* Get Adapter Name
*
* @return string
*/
public function getName(): string
{
return 'gogs';
}

protected function getHookType(): string
{
return 'gogs';
}

/**
* Get commit statuses
*
* Overrides the Gitea implementation to normalise the 'state' field
* returned by Gogs into the 'status' field used by the rest of the
* adapter interface (Gitea changed the JSON key from 'state' to
* 'status', but Gogs still uses 'state').
*
* @param string $owner Owner of the repository
* @param string $repositoryName Name of the repository
* @param string $commitHash SHA of the commit
* @return array<mixed> List of commit statuses
*/
public function getCommitStatuses(string $owner, string $repositoryName, string $commitHash): array
{
$statuses = parent::getCommitStatuses($owner, $repositoryName, $commitHash);

return array_map(function ($status) {
if (isset($status['state']) && !isset($status['status'])) {
$status['status'] = $status['state'];
}
return $status;
}, $statuses);
}
}
62 changes: 62 additions & 0 deletions tests/VCS/Adapter/GogsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Utopia\Tests\Adapter;

use Utopia\Cache\Adapter\None;
use Utopia\Cache\Cache;
use Utopia\System\System;
use Utopia\VCS\Adapter\Git;
use Utopia\VCS\Adapter\Git\Gogs;

class GogsTest extends GiteaTest
{
protected static string $accessToken = '';

protected static string $owner = '';

protected string $webhookEventHeader = 'X-Gogs-Event';
protected string $webhookSignatureHeader = 'X-Gogs-Signature';
protected string $avatarDomain = 'gravatar.com';

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

public function setUp(): void
{
if (empty(static::$accessToken)) {
$this->setupGogs();
}

$adapter = new Gogs(new Cache(new None()));
$gogsUrl = System::getEnv('TESTS_GOGS_URL', 'http://gogs:3000') ?? '';

$adapter->initializeVariables(
installationId: '',
privateKey: '',
appId: '',
accessToken: static::$accessToken,
refreshToken: ''
);
$adapter->setEndpoint($gogsUrl);
if (empty(static::$owner)) {
$orgName = 'test-org-' . \uniqid();
static::$owner = $adapter->createOrganization($orgName);
}

$this->vcsAdapter = $adapter;
}

protected function setupGogs(): void
{
$tokenFile = '/gogs-data/gogs/token.txt';

if (file_exists($tokenFile)) {
$contents = file_get_contents($tokenFile);
if ($contents !== false) {
static::$accessToken = trim($contents);
}
}
}
}
36 changes: 36 additions & 0 deletions tests/resources/gogs-custom/conf/app.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
APP_NAME = Gogs
RUN_MODE = prod
RUN_USER = git

[server]
DOMAIN = gogs
HTTP_PORT = 3000
ROOT_URL = http://gogs:3000/
LOCAL_ROOT_URL = http://gogs:3000/
DISABLE_SSH = true

[database]
DB_TYPE = sqlite3
PATH = /data/gogs.db

[repository]
ROOT = /data/repositories

[security]
INSTALL_LOCK = true
# SECRET_KEY is intentionally hardcoded — this config is for local/CI testing only.
SECRET_KEY = verySecretGogsKey1234567890

[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = false

[webhook]
DELIVER_TIMEOUT = 10
SKIP_TLS_VERIFY = true

[log]
MODE = console
LEVEL = Info
Loading