From cdf5bb2fcf830d631427e2c7e7be00235f7a669d Mon Sep 17 00:00:00 2001 From: priya-sundaram-dev Date: Thu, 3 Sep 2026 05:14:02 +0000 Subject: [PATCH 1/2] scripts: de-duplicate and harden the close_pull_requests_with_*.sh backlog jobs Extract the five byte-for-byte-identical backlog-closing scripts into one parameterized close_pull_requests_with_label.sh and make each named script a thin wrapper. Addresses the recommendations from #15168: - Correctness: filter by label server-side (gh pr list --label) instead of listing all ~900 open PRs and matching client-side, so no PR is skipped by an arbitrary --limit cap. - De-duplication: one implementation removes the drift between copies (some had sleep 2, one had it commented out, two had none). - Throttling: a single, deliberate SLEEP (default 2s) between closes. - Safety rails: set -euo pipefail, explicit --repo, and a DRY_RUN=1 preview mode that prints what would close before a maintainer commits. - Machine-readable summary (CLOSED_COUNT/CLOSED_PRS) so the Hacktoberfest tracker can be updated from script output. Follow-up to #15081. --- ...ose_pull_requests_with_awaiting_changes.sh | 27 ++------ .../close_pull_requests_with_failing_tests.sh | 27 ++------ scripts/close_pull_requests_with_label.sh | 63 +++++++++++++++++++ ...requests_with_require_descriptive_names.sh | 26 ++------ .../close_pull_requests_with_require_tests.sh | 27 ++------ ...e_pull_requests_with_require_type_hints.sh | 26 ++------ 6 files changed, 93 insertions(+), 103 deletions(-) create mode 100755 scripts/close_pull_requests_with_label.sh diff --git a/scripts/close_pull_requests_with_awaiting_changes.sh b/scripts/close_pull_requests_with_awaiting_changes.sh index 55e19c980596..3ea8445394d9 100755 --- a/scripts/close_pull_requests_with_awaiting_changes.sh +++ b/scripts/close_pull_requests_with_awaiting_changes.sh @@ -1,22 +1,7 @@ #!/bin/bash - -# List all open pull requests -prs=$(gh pr list --state open --json number,title,labels --limit 500) - -# Loop through each pull request -echo "$prs" | jq -c '.[]' | while read -r pr; do - pr_number=$(echo "$pr" | jq -r '.number') - pr_title=$(echo "$pr" | jq -r '.title') - pr_labels=$(echo "$pr" | jq -r '.labels') - - # Check if the "awaiting changes" label is present - awaiting_changes=$(echo "$pr_labels" | jq -r '.[] | select(.name == "awaiting changes")') - echo "Checking PR #$pr_number $pr_title ($awaiting_changes) ($pr_labels)" - - # If awaiting_changes, close the pull request - if [[ -n "$awaiting_changes" ]]; then - echo "Closing PR #$pr_number $pr_title due to awaiting_changes label" - gh pr close "$pr_number" --comment "Closing awaiting_changes PRs to prepare for Hacktoberfest" - sleep 2 - fi -done +# +# Close every open pull request labelled "awaiting changes". +# Thin wrapper around close_pull_requests_with_label.sh so all five backlog +# jobs share one implementation. Set DRY_RUN=1 to preview. +set -euo pipefail +exec "$(dirname "$0")/close_pull_requests_with_label.sh" "awaiting changes" "$@" diff --git a/scripts/close_pull_requests_with_failing_tests.sh b/scripts/close_pull_requests_with_failing_tests.sh index 3ec5960aed27..1acaefaa35ee 100755 --- a/scripts/close_pull_requests_with_failing_tests.sh +++ b/scripts/close_pull_requests_with_failing_tests.sh @@ -1,22 +1,7 @@ #!/bin/bash - -# List all open pull requests -prs=$(gh pr list --state open --json number,title,labels --limit 500) - -# Loop through each pull request -echo "$prs" | jq -c '.[]' | while read -r pr; do - pr_number=$(echo "$pr" | jq -r '.number') - pr_title=$(echo "$pr" | jq -r '.title') - pr_labels=$(echo "$pr" | jq -r '.labels') - - # Check if the "tests are failing" label is present - tests_are_failing=$(echo "$pr_labels" | jq -r '.[] | select(.name == "tests are failing")') - echo "Checking PR #$pr_number $pr_title ($tests_are_failing) ($pr_labels)" - - # If there are failing tests, close the pull request - if [[ -n "$tests_are_failing" ]]; then - echo "Closing PR #$pr_number $pr_title due to tests_are_failing label" - gh pr close "$pr_number" --comment "Closing tests_are_failing PRs to prepare for Hacktoberfest" - sleep 2 - fi -done +# +# Close every open pull request labelled "tests are failing". +# Thin wrapper around close_pull_requests_with_label.sh so all five backlog +# jobs share one implementation. Set DRY_RUN=1 to preview. +set -euo pipefail +exec "$(dirname "$0")/close_pull_requests_with_label.sh" "tests are failing" "$@" diff --git a/scripts/close_pull_requests_with_label.sh b/scripts/close_pull_requests_with_label.sh new file mode 100755 index 000000000000..bdf7d19f2b51 --- /dev/null +++ b/scripts/close_pull_requests_with_label.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# +# Close every open pull request that carries a given label, leaving an +# explanatory comment. This is used to clear the backlog before Hacktoberfest. +# +# Usage: +# scripts/close_pull_requests_with_label.sh "