|
8 | 8 | use Utopia\Tests\Base; |
9 | 9 | use Utopia\VCS\Adapter\Git; |
10 | 10 | use Utopia\VCS\Adapter\Git\Gitea; |
11 | | -use Utopia\Fetch\Client; |
12 | 11 |
|
13 | 12 | class GiteaTest extends Base |
14 | 13 | { |
@@ -57,71 +56,6 @@ private function setupGitea(): void |
57 | 56 | } |
58 | 57 | } |
59 | 58 |
|
60 | | - private function configureWebhook(string $owner, string $repositoryName, string $secret): int |
61 | | - { |
62 | | - $catcherUrl = System::getEnv('TESTS_GITEA_REQUEST_CATCHER_URL', 'http://request-catcher:5000') ?? ''; |
63 | | - |
64 | | - return $this->vcsAdapter->createWebhook( |
65 | | - $owner, |
66 | | - $repositoryName, |
67 | | - $catcherUrl . '/webhook', |
68 | | - $secret |
69 | | - ); |
70 | | - } |
71 | | - |
72 | | - /** @return array<mixed> */ |
73 | | - private function getLastWebhookRequest(): array |
74 | | - { |
75 | | - $catcherUrl = System::getEnv('TESTS_GITEA_REQUEST_CATCHER_URL', 'http://request-catcher:5000') ?? ''; |
76 | | - |
77 | | - $client = new Client(); |
78 | | - $response = $client->fetch( |
79 | | - url: "{$catcherUrl}/__last_request__", |
80 | | - method: 'GET' |
81 | | - ); |
82 | | - |
83 | | - if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |
84 | | - return []; |
85 | | - } |
86 | | - |
87 | | - $body = $response->text(); |
88 | | - |
89 | | - if (empty($body)) { |
90 | | - return []; |
91 | | - } |
92 | | - |
93 | | - return json_decode($body, true) ?? []; |
94 | | - } |
95 | | - |
96 | | - private function assertEventually(callable $probe, int $timeoutMs = 15000, int $waitMs = 500): void |
97 | | - { |
98 | | - $start = microtime(true) * 1000; |
99 | | - $lastException = null; |
100 | | - |
101 | | - while ((microtime(true) * 1000 - $start) < $timeoutMs) { |
102 | | - try { |
103 | | - $probe(); |
104 | | - return; |
105 | | - } catch (\Throwable $e) { |
106 | | - $lastException = $e; |
107 | | - usleep($waitMs * 1000); |
108 | | - } |
109 | | - } |
110 | | - |
111 | | - throw $lastException ?? new \Exception('assertEventually timed out'); |
112 | | - } |
113 | | - |
114 | | - private function clearWebhookRequests(): void |
115 | | - { |
116 | | - $catcherUrl = System::getEnv('TESTS_GITEA_REQUEST_CATCHER_URL', 'http://request-catcher:5000') ?? ''; |
117 | | - |
118 | | - $client = new Client(); |
119 | | - $client->fetch( |
120 | | - url: "{$catcherUrl}/__clear__", |
121 | | - method: 'DELETE' |
122 | | - ); |
123 | | - } |
124 | | - |
125 | 59 | public function testCreateRepository(): void |
126 | 60 | { |
127 | 61 | $owner = self::$owner; |
@@ -1308,8 +1242,9 @@ public function testWebhookPushEvent(): void |
1308 | 1242 | $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false); |
1309 | 1243 |
|
1310 | 1244 | try { |
1311 | | - $this->clearWebhookRequests(); |
1312 | | - $this->configureWebhook(self::$owner, $repositoryName, $secret); |
| 1245 | + $catcherUrl = System::getEnv('TESTS_GITEA_REQUEST_CATCHER_URL', 'http://request-catcher:5000') ?? ''; |
| 1246 | + $this->deleteLastWebhookRequest(); |
| 1247 | + $this->vcsAdapter->createWebhook(self::$owner, $repositoryName, $catcherUrl . '/webhook', $secret); |
1313 | 1248 |
|
1314 | 1249 | // Trigger a real push by creating a file |
1315 | 1250 | $this->vcsAdapter->createFile( |
@@ -1364,10 +1299,11 @@ public function testWebhookPullRequestEvent(): void |
1364 | 1299 | $this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'feature-branch', 'main'); |
1365 | 1300 | $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'feature.txt', 'content', 'Add feature', 'feature-branch'); |
1366 | 1301 |
|
1367 | | - $this->configureWebhook(self::$owner, $repositoryName, $secret); |
| 1302 | + $catcherUrl = System::getEnv('TESTS_GITEA_REQUEST_CATCHER_URL', 'http://request-catcher:5000') ?? ''; |
| 1303 | + $this->vcsAdapter->createWebhook(self::$owner, $repositoryName, $catcherUrl . '/webhook', $secret); |
1368 | 1304 |
|
1369 | 1305 | // Clear after setup so only PR event will arrive |
1370 | | - $this->clearWebhookRequests(); |
| 1306 | + $this->deleteLastWebhookRequest(); |
1371 | 1307 |
|
1372 | 1308 | // Trigger real PR event |
1373 | 1309 | $this->vcsAdapter->createPullRequest( |
|
0 commit comments