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 <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-02-11 20:39:21 +13:00
co-authored by Claude Opus 4.6
parent 32c617a149
commit bc69154024
+20 -13
View File
@@ -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'];
}
}
}