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
+28 -20
View File
@@ -16,33 +16,41 @@ curl_with_host() {
declare -A BRANCH_CACHE
branch_exists() {
local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}"
local status
local status attempt
[ -z "$GITEA_API_URL" ] && return 0
[ -z "$GITEA_TOKEN" ] && return 0
if [ "${BRANCH_CACHE[$key]:-}" = "1" ]; then
return 0
fi
status=$(curl -sS -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000")
if [ "$status" = "200" ]; then
BRANCH_CACHE[$key]=1
return 0
fi
# API error or branch not found - log warning and keep report (fail-safe)
if [ "$status" != "404" ]; then
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
# 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}" \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000")
if [ "$status" = "200" ]; then
BRANCH_CACHE[$key]=1
return 0
fi
if [ "$status" = "404" ]; then
return 1
fi
# API error - retry if not last attempt
if [ "$attempt" -lt 3 ]; then
sleep 10
continue
fi
done
# Actual 404 - branch truly doesn't exist
return 1
# 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")