@@ -18,8 +18,8 @@ REPO="$1"
1818echo " Checking for open Dependabot PRs to approve and merge in $REPO ..."
1919
2020# Get all open PRs from dependabot
21- dependabot_prs= $( gh pr list -R " $REPO " --author " dependabot[bot] " --state open --json number,title,reviews )
22-
21+ # We filter so that only PRs that are not from forks and are in branches starting with "dependabot/cargo" are included.
22+ dependabot_prs= $( gh pr list -R " $REPO " --author " dependabot[bot] " --state open --json number,title,reviews,headRepositoryOwner,headRefName | jq --arg repo_owner " $( echo " $REPO " | cut -d ' / ' -f1 ) " ' [.[] | select(.headRepositoryOwner.login == $repo_owner and (.headRefName | startswith("dependabot/cargo")))] ' )
2323# Exit early if no PRs found
2424if [ -z " $dependabot_prs " ] || [ " $dependabot_prs " = " []" ]; then
2525 echo " No open Dependabot PRs found in $REPO "
@@ -39,17 +39,17 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
3939
4040 # Check if PR only modifies allowed files
4141 pr_files=$( gh pr view " $pr_number " -R " $REPO " --json files)
42- invalid_files=$( echo " $pr_files " | jq -r ' .files[].path' | grep -v -E ' (Cargo\.toml|Cargo\.lock|\.github/workflows/.+ )' || true)
42+ invalid_files=$( echo " $pr_files " | jq -r ' .files[].path' | grep -v -E ' (Cargo\.toml|Cargo\.lock)' || true)
4343
4444 if [ -n " $invalid_files " ]; then
4545 echo " ❌ PR #$pr_number modifies files that are not allowed for auto-merge:"
4646 echo ${invalid_files/#/ - }
47- echo " ℹ️ Only changes to Cargo.toml, Cargo.lock, or .github/workflows/ files are allowed"
47+ echo " ℹ️ Only changes to Cargo.toml and Cargo.lock are allowed"
4848 continue
4949 fi
50-
51- echo " ✅ PR #$pr_number only modifies allowed files (Cargo.toml, Cargo.lock, or .github/workflows/ )"
52-
50+
51+ echo " ✅ PR #$pr_number only modifies allowed files (Cargo.toml and Cargo.lock)"
52+
5353 # First, get detailed PR information including all checks
5454 pr_details=$( gh pr view " $pr_number " -R " $REPO " --json statusCheckRollup,state)
5555
@@ -58,16 +58,27 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
5858 has_pending_checks=false
5959 failed_checks=" "
6060
61- # First identify checks that are still in progress
61+ # First identify checks that are still in progress
6262 pending_checks=$( echo " $pr_details " | jq -r ' .statusCheckRollup[] | select(.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "PENDING") | .name' )
6363
64+ # Check for permission-required checks
65+ permission_required_checks=$( echo " $pr_details " | jq -r ' .statusCheckRollup[] | select(.status == "WAITING" or .status == "ACTION_REQUIRED" or (.status == "QUEUED" and .conclusion == null and .detailsUrl != null and (.detailsUrl | contains("waiting-for-approval")))) | .name' )
66+
67+ # Dont approve if there are checks required that need permission to run
68+ if [ -n " $permission_required_checks " ]; then
69+ echo " 🔐 PR #$pr_number has checks waiting for permission:"
70+ echo " $permission_required_checks " | sed ' s/^/ - /'
71+ echo " ❌ Skipping auto-approval due to permission-required checks"
72+ continue
73+ fi
74+
6475 if [ -n " $pending_checks " ]; then
6576 echo " ⏳ PR #$pr_number has pending checks:"
6677 echo " $pending_checks " | sed ' s/^/ - /'
6778 echo " ℹ️ We will still approve the PR so it can merge automatically once all checks pass"
6879 has_pending_checks=true
6980 fi
70-
81+
7182 # Check for failed checks - only include checks that have a conclusion and are not still running
7283 # Explicitly exclude checks with status IN_PROGRESS, QUEUED, or PENDING
7384 failed_checks=$( echo " $pr_details " | jq -r ' .statusCheckRollup[] |
0 commit comments