fix(retention): fix branch cache and deduplication bugs
- Convert BRANCH_CACHE from string to associative array - Add SEEN_REPORTS deduplication to prevent processing duplicate reports - Initialize BRANCH_COUNTS associative array before use - Fixes main branch reports being incorrectly deleted
This commit is contained in:
@@ -13,7 +13,7 @@ curl_with_host() {
|
|||||||
|
|
||||||
[ -f "$CONFIG" ] || { echo "ERROR: config missing: $CONFIG" >&2; exit 1; }
|
[ -f "$CONFIG" ] || { echo "ERROR: config missing: $CONFIG" >&2; exit 1; }
|
||||||
|
|
||||||
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
|
||||||
@@ -21,7 +21,7 @@ branch_exists() {
|
|||||||
[ -z "$GITEA_API_URL" ] && return 0
|
[ -z "$GITEA_API_URL" ] && return 0
|
||||||
[ -z "$GITEA_TOKEN" ] && return 0
|
[ -z "$GITEA_TOKEN" ] && return 0
|
||||||
|
|
||||||
if grep -q "^${key}$" <<< "$BRANCH_CACHE" 2>/dev/null; then
|
if [ "${BRANCH_CACHE[$key]:-}" = "1" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ branch_exists() {
|
|||||||
"${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")
|
||||||
|
|
||||||
if [ "$status" = "200" ]; then
|
if [ "$status" = "200" ]; then
|
||||||
BRANCH_CACHE="${BRANCH_CACHE}${key}"$'\n'
|
BRANCH_CACHE[$key]=1
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
@@ -79,9 +79,15 @@ fi
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Phase 1: collect reports ==="
|
echo "=== Phase 1: collect reports ==="
|
||||||
|
declare -A SEEN_REPORTS
|
||||||
declare -a REPORTS
|
declare -a REPORTS
|
||||||
while IFS= read -r meta_path; do
|
while IFS= read -r meta_path; do
|
||||||
report_dir=$(dirname "$meta_path")
|
report_dir=$(dirname "$meta_path")
|
||||||
|
|
||||||
|
# Skip duplicates - same report dir already processed
|
||||||
|
[ -z "${SEEN_REPORTS[$report_dir]:-}" ] || continue
|
||||||
|
SEEN_REPORTS[$report_dir]=1
|
||||||
|
|
||||||
parse_path "$report_dir"
|
parse_path "$report_dir"
|
||||||
meta_content=$(curl_with_host "${PAGES_URL}/${meta_path}" 2>/dev/null || true)
|
meta_content=$(curl_with_host "${PAGES_URL}/${meta_path}" 2>/dev/null || true)
|
||||||
[ -n "$meta_content" ] || { echo " WARN: could not fetch $meta_path"; continue; }
|
[ -n "$meta_content" ] || { echo " WARN: could not fetch $meta_path"; continue; }
|
||||||
@@ -121,6 +127,7 @@ done
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Phase 3: apply retention rules to remaining reports ==="
|
echo "=== Phase 3: apply retention rules to remaining reports ==="
|
||||||
|
declare -A BRANCH_COUNTS
|
||||||
if [ "${#KEEP[@]}" -gt 0 ]; then
|
if [ "${#KEEP[@]}" -gt 0 ]; then
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for entry in $(printf '%s\n' "${KEEP[@]}" | sort -t'|' -k4,4 -k5,5rn); do
|
for entry in $(printf '%s\n' "${KEEP[@]}" | sort -t'|' -k4,4 -k5,5rn); do
|
||||||
|
|||||||
Reference in New Issue
Block a user