diff --git a/.github/workflows/clear_old_branches.yml b/.github/workflows/clear_old_branches.yml index 76203b9ba..5e68a9f26 100644 --- a/.github/workflows/clear_old_branches.yml +++ b/.github/workflows/clear_old_branches.yml @@ -32,7 +32,10 @@ jobs: --base main \ --json number,state,mergedAt,closedAt,headRefName \ --limit 500 | - jq -r '.[] | select(.state == "MERGED" or .state == "CLOSED") | .headRefName' | + jq -r --arg cutoff "$CUTOFF_DATE" '.[] | + select(.state == "MERGED" or .state == "CLOSED") | + select(((.mergedAt // .closedAt) | fromdateiso8601) < ($cutoff | tonumber)) | + .headRefName' | sort -u | while read -r branch; do # Schutz @@ -45,17 +48,11 @@ jobs: echo "Checking if branch still exists: $branch" if gh api -X GET repos/${{ github.repository }}/git/refs/heads/$branch 2>/dev/null; then - CLOSED_OR_MERGED_TS=$(date -d "$branch" +%s 2>/dev/null || date +%s) - - if [ "$CLOSED_OR_MERGED_TS" -lt "$CUTOFF_DATE" ]; then - echo "Deleting branch: $branch" - gh api \ - -X DELETE \ - repos/${{ github.repository }}/git/refs/heads/$branch \ - || echo "Failed to delete branch $branch" - else - echo "Keeping branch: $branch (recent)" - fi + echo "Deleting branch: $branch" + gh api \ + -X DELETE \ + repos/${{ github.repository }}/git/refs/heads/$branch \ + || echo "Failed to delete branch $branch" else echo "Branch $branch does not exist (already deleted)" fi