-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathForgejoTest.php
More file actions
56 lines (45 loc) · 1.52 KB
/
ForgejoTest.php
File metadata and controls
56 lines (45 loc) · 1.52 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
<?php
namespace Utopia\Tests\Adapter;
use Utopia\Cache\Adapter\None;
use Utopia\Cache\Cache;
use Utopia\System\System;
use Utopia\VCS\Adapter\Git\Forgejo;
class ForgejoTest extends GiteaTest
{
protected static string $accessToken = '';
protected static string $owner = '';
protected string $webhookEventHeader = 'X-Forgejo-Event';
protected string $webhookSignatureHeader = 'X-Forgejo-Signature';
protected string $avatarDomain = 'http://localhost:3000/avatars/';
public function setupAdapter(): void
{
if (empty(static::$accessToken)) {
$this->setupForgejo();
}
$adapter = new Forgejo(new Cache(new None()));
$forgejoUrl = System::getEnv('TESTS_FORGEJO_URL', 'http://forgejo:3000');
$adapter->initializeVariables(
installationId: '',
privateKey: '',
appId: '',
accessToken: static::$accessToken,
refreshToken: ''
);
$adapter->setEndpoint($forgejoUrl);
if (empty(static::$owner)) {
$orgName = 'test-org-' . \uniqid();
static::$owner = $adapter->createOrganization($orgName);
}
$this->vcsAdapter = $adapter;
}
protected function setupForgejo(): void
{
$tokenFile = '/forgejo-data/gitea/token.txt';
if (file_exists($tokenFile)) {
$contents = file_get_contents($tokenFile);
if ($contents !== false) {
static::$accessToken = trim($contents);
}
}
}
}