From bc69154024886850ab643f5bfa842e670b968860 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 11 Feb 2026 20:39:21 +1300 Subject: [PATCH] fix: add retry logic to helperGetLatestCommit for GitHub API rate limits The testCreateSiteFromTemplateCommit test fails intermittently when the unauthenticated GitHub API call gets rate limited, returning null. Added 3 retries with 5s delay to handle transient failures. Co-Authored-By: Claude Opus 4.6 --- tests/e2e/Services/Sites/SitesBase.php | 33 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index e7af09d1d9..239237c8b1 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -335,21 +335,28 @@ trait SitesBase protected function helperGetLatestCommit(string $owner, string $repository): ?string { - $ch = curl_init("https://api.github.com/repos/{$owner}/{$repository}/commits/main"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'User-Agent: Appwrite', - 'Accept: application/vnd.github.v3+json' - ]); + $maxRetries = 3; + for ($attempt = 0; $attempt < $maxRetries; $attempt++) { + if ($attempt > 0) { + sleep(5); + } - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); + $ch = curl_init("https://api.github.com/repos/{$owner}/{$repository}/commits/main"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'User-Agent: Appwrite', + 'Accept: application/vnd.github.v3+json' + ]); - if ($httpCode === 200) { - $commitData = json_decode($response, true); - if (isset($commitData['sha'])) { - return $commitData['sha']; + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($httpCode === 200) { + $commitData = json_decode($response, true); + if (isset($commitData['sha'])) { + return $commitData['sha']; + } } }