-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGogsTest.php
More file actions
62 lines (50 loc) · 1.59 KB
/
GogsTest.php
File metadata and controls
62 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}
}
}
}