fix(retention): add retry on Gitea API errors
CI / Load gitea-env.conf to pipeline env (push) Successful in 12s
ci-cucumber Cucumber tests
ci-bats Bats tests
ci-build Build complete
CI / Quality Gate (push) Successful in 2m17s
CI / Build & Push Artifact (push) Has been skipped

- Retry up to 3 times (2 retries) on non-200/non-404 responses
- 10 second delay between retries
- Fail-safe: keep report if all retries fail
This commit is contained in:
moilanik
2026-06-14 09:16:37 +03:00
parent 622e8acdc5
commit 5ac7516672
+16 -8
View File
@@ -16,7 +16,7 @@ curl_with_host() {
declare -A BRANCH_CACHE declare -A BRANCH_CACHE
branch_exists() { branch_exists() {
local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}" local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}"
local status local status attempt
[ -z "$GITEA_API_URL" ] && return 0 [ -z "$GITEA_API_URL" ] && return 0
[ -z "$GITEA_TOKEN" ] && return 0 [ -z "$GITEA_TOKEN" ] && return 0
@@ -25,6 +25,8 @@ branch_exists() {
return 0 return 0
fi fi
# Retry up to 2 times on API errors (hardcoded)
for attempt in 1 2 3; do
status=$(curl -sS -o /dev/null -w "%{http_code}" \ status=$(curl -sS -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${GITEA_TOKEN}" \ -H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000") "${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000")
@@ -34,15 +36,21 @@ branch_exists() {
return 0 return 0
fi fi
# API error or branch not found - log warning and keep report (fail-safe) if [ "$status" = "404" ]; then
if [ "$status" != "404" ]; then return 1
echo " WARN: Gitea API error for ${owner}/${repo}/${branch} (status ${status}) - KEEPING report"
BRANCH_CACHE[$key]=1 # cache as "exists" to avoid repeated errors
return 0
fi fi
# Actual 404 - branch truly doesn't exist # API error - retry if not last attempt
return 1 if [ "$attempt" -lt 3 ]; then
sleep 10
continue
fi
done
# All retries failed - keep report (fail-safe)
echo " WARN: Gitea API error for ${owner}/${repo}/${branch} (status ${status}) after 3 attempts - KEEPING report"
BRANCH_CACHE[$key]=1
return 0
} }
default_max_age=$(jq -r '.branches.default.maxAgeDays // 90' "$CONFIG") default_max_age=$(jq -r '.branches.default.maxAgeDays // 90' "$CONFIG")