From 97020caf892f467fc234de8934e6c6434bd0babc Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 28 Aug 2024 13:33:35 +0300 Subject: [PATCH] fix script to not close PRs other than those starting with chore/update-preview --- .github/workflows/update-preview-deps-ci.yml | 24 +++++++++++--------- .github/workflows/update-preview-deps.yml | 24 +++++++++++--------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.github/workflows/update-preview-deps-ci.yml b/.github/workflows/update-preview-deps-ci.yml index c561edbe..67fadbe7 100644 --- a/.github/workflows/update-preview-deps-ci.yml +++ b/.github/workflows/update-preview-deps-ci.yml @@ -33,19 +33,21 @@ jobs: shell: "bash" run: | - # Get the list of pull requests with the specified title - PR_LIST=$(gh pr list --base feat/v2-ci --json number) - - echo "$PR_LIST" - - # Check if any pull requests were found - if [ -z "$PR_LIST" ]; then - echo "No pull requests found on branch feat/v2-ci" + PR_LIST=$(gh pr list --base feat/v2-ci --json number,headRefName) + + # Filter out PRs where headRefName starts with 'chore/update-preview' + FILTERED_PR_LIST=$(echo "$PR_LIST" | jq '[.[] | select(.headRefName | test("^chore/update-preview"))]') + + echo "$FILTERED_PR_LIST" + + # Check if any pull requests were found after filtering + if [ -z "$FILTERED_PR_LIST" ] || [ "$FILTERED_PR_LIST" = "[]" ]; then + echo "No pull requests found on branch feat/v2-ci after filtering" exit 0 fi - - # Close each pull request - echo "$PR_LIST" | jq -r '.[].number' | while read -r PR_NUMBER; do + + # Close each filtered pull request + echo "$FILTERED_PR_LIST" | jq -r '.[].number' | while read -r PR_NUMBER; do echo "Closing pull request #$PR_NUMBER" gh pr close "$PR_NUMBER" -d done diff --git a/.github/workflows/update-preview-deps.yml b/.github/workflows/update-preview-deps.yml index 47b039ea..950edc7a 100644 --- a/.github/workflows/update-preview-deps.yml +++ b/.github/workflows/update-preview-deps.yml @@ -33,19 +33,21 @@ jobs: shell: "bash" run: | - # Get the list of pull requests with the specified title - PR_LIST=$(gh pr list --base feat/v2 --json number) - - echo "$PR_LIST" - - # Check if any pull requests were found - if [ -z "$PR_LIST" ]; then - echo "No pull requests found on branch feat/v2" + PR_LIST=$(gh pr list --base feat/v2 --json number,headRefName) + + # Filter out PRs where headRefName starts with 'chore/update-preview' + FILTERED_PR_LIST=$(echo "$PR_LIST" | jq '[.[] | select(.headRefName | test("^chore/update-preview"))]') + + echo "$FILTERED_PR_LIST" + + # Check if any pull requests were found after filtering + if [ -z "$FILTERED_PR_LIST" ] || [ "$FILTERED_PR_LIST" = "[]" ]; then + echo "No pull requests found on branch feat/v2 after filtering" exit 0 fi - - # Close each pull request - echo "$PR_LIST" | jq -r '.[].number' | while read -r PR_NUMBER; do + + # Close each filtered pull request + echo "$FILTERED_PR_LIST" | jq -r '.[].number' | while read -r PR_NUMBER; do echo "Closing pull request #$PR_NUMBER" gh pr close "$PR_NUMBER" -d done