|
|
|
|
@@ -35,7 +35,7 @@ for arg in "$@"; do
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
API="$GITEA_URL/api/v1"
|
|
|
|
|
AUTH="token $GITEA_TOKEN"
|
|
|
|
|
AUTH="Authorization: token $GITEA_TOKEN"
|
|
|
|
|
|
|
|
|
|
log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*"; }
|
|
|
|
|
|
|
|
|
|
@@ -148,6 +148,51 @@ if [ "$DUPLICATES_FOUND" -eq 0 ]; then
|
|
|
|
|
log "No duplicate PRs found"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ─── Additional cleanup: Stale branches from closed/merged PRs ───
|
|
|
|
|
log "Checking for stale branches from closed/merged PRs..."
|
|
|
|
|
|
|
|
|
|
ALL_PRS=$(curl -s -H "$AUTH" "$API/repos/$REPO/pulls?state=closed&limit=100")
|
|
|
|
|
STALE_BRANCHES_DELETED=0
|
|
|
|
|
|
|
|
|
|
if [ -n "$ALL_PRS" ] && [ "$ALL_PRS" != "null" ]; then
|
|
|
|
|
echo "$ALL_PRS" | jq -r '.[] | select(.merged == false) | "\(.number)\t(.head.ref)\t\(.state)"' | while IFS=$'\t' read -r pr_num pr_branch pr_state; do
|
|
|
|
|
[ -z "$pr_branch" ] && continue
|
|
|
|
|
# Skip if branch doesn't exist
|
|
|
|
|
branch_check=$(curl -s -o /dev/null -w "%{http_code}" -H "$AUTH" "$API/repos/$REPO/branches/$pr_branch")
|
|
|
|
|
if [ "$branch_check" != "200" ]; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
log "Stale branch from closed PR #$pr_num: $pr_branch"
|
|
|
|
|
if [ "$DRY_RUN" = "true" ]; then
|
|
|
|
|
log "DRY RUN: Would delete branch $pr_branch"
|
|
|
|
|
else
|
|
|
|
|
curl -s -X DELETE -H "$AUTH" "$API/repos/$REPO/branches/$pr_branch" > /dev/null
|
|
|
|
|
log "Deleted branch $pr_branch"
|
|
|
|
|
STALE_BRANCHES_DELETED=$((STALE_BRANCHES_DELETED + 1))
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ─── Additional cleanup: Stale branches from merged PRs ───
|
|
|
|
|
log "Checking for stale branches from merged PRs..."
|
|
|
|
|
|
|
|
|
|
if [ -n "$ALL_PRS" ] && [ "$ALL_PRS" != "null" ]; then
|
|
|
|
|
echo "$ALL_PRS" | jq -r '.[] | select(.merged == true) | "\(.number)\t\(.head.ref)"' | while IFS=$'\t' read -r pr_num pr_branch; do
|
|
|
|
|
[ -z "$pr_branch" ] && continue
|
|
|
|
|
branch_check=$(curl -s -o /dev/null -w "%{http_code}" -H "$AUTH" "$API/repos/$REPO/branches/$pr_branch")
|
|
|
|
|
if [ "$branch_check" != "200" ]; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
log "Stale branch from merged PR #$pr_num: $pr_branch"
|
|
|
|
|
if [ "$DRY_RUN" = "true" ]; then
|
|
|
|
|
log "DRY RUN: Would delete branch $pr_branch"
|
|
|
|
|
else
|
|
|
|
|
curl -s -X DELETE -H "$AUTH" "$API/repos/$REPO/branches/$pr_branch" > /dev/null
|
|
|
|
|
log "Deleted branch $pr_branch"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ─── Additional cleanup: Stale PRs ────────────────────────
|
|
|
|
|
# Check for PRs older than 30 days with no activity
|
|
|
|
|
log "Checking for stale PRs (older than 30 days)..."
|
|
|
|
|
|