@@ -18,8 +18,8 @@ REPO="$1"
18
18
echo " Checking for open Dependabot PRs to approve and merge in $REPO ..."
19
19
20
20
# 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")))] ' )
23
23
# Exit early if no PRs found
24
24
if [ -z " $dependabot_prs " ] || [ " $dependabot_prs " = " []" ]; then
25
25
echo " No open Dependabot PRs found in $REPO "
@@ -39,17 +39,17 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
39
39
40
40
# Check if PR only modifies allowed files
41
41
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)
43
43
44
44
if [ -n " $invalid_files " ]; then
45
45
echo " ❌ PR #$pr_number modifies files that are not allowed for auto-merge:"
46
46
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"
48
48
continue
49
49
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
+
53
53
# First, get detailed PR information including all checks
54
54
pr_details=$( gh pr view " $pr_number " -R " $REPO " --json statusCheckRollup,state)
55
55
@@ -58,16 +58,27 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
58
58
has_pending_checks=false
59
59
failed_checks=" "
60
60
61
- # First identify checks that are still in progress
61
+ # First identify checks that are still in progress
62
62
pending_checks=$( echo " $pr_details " | jq -r ' .statusCheckRollup[] | select(.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "PENDING") | .name' )
63
63
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
+
64
75
if [ -n " $pending_checks " ]; then
65
76
echo " ⏳ PR #$pr_number has pending checks:"
66
77
echo " $pending_checks " | sed ' s/^/ - /'
67
78
echo " ℹ️ We will still approve the PR so it can merge automatically once all checks pass"
68
79
has_pending_checks=true
69
80
fi
70
-
81
+
71
82
# Check for failed checks - only include checks that have a conclusion and are not still running
72
83
# Explicitly exclude checks with status IN_PROGRESS, QUEUED, or PENDING
73
84
failed_checks=$( echo " $pr_details " | jq -r ' .statusCheckRollup[] |
0 commit comments