Skip to content

Commit cddf8b5

Browse files
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1da23d1 commit cddf8b5

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

.github/workflows/auto-merge-dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
# This workflow uses a GitHub App token to approve and merge Dependabot PRs
1010
# The token is created using the `actions/create-github-app-token` action
11-
# The token is used so that the updates are made by the GitHub App instead of Github Actions
11+
# The token is used so that the updates are made by the GitHub App instead of GitHub Actions
1212
# and will show up as such in the PR comments and history
1313
# In addition, the token is scoped to only the permissions needed for this workflow
1414
# see https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow for details

scripts/auto-approve-dependabot.sh

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
4343

4444
if [ -n "$invalid_files" ]; then
4545
echo " ❌ PR #$pr_number modifies files that are not allowed for auto-merge:"
46-
echo ${invalid_files/#/ - }
46+
printf '%s\n' "$invalid_files" | sed 's/^/ - /'
4747
echo " ℹ️ Only changes to Cargo.toml and Cargo.lock are allowed"
4848
continue
4949
fi
@@ -64,7 +64,7 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
6464
# Check for permission-required checks
6565
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')
6666

67-
# Dont approve if there are checks required that need permission to run
67+
# Don't approve if there are checks required that need permission to run
6868
if [ -n "$permission_required_checks" ]; then
6969
echo " 🔐 PR #$pr_number has checks waiting for permission:"
7070
echo "$permission_required_checks" | sed 's/^/ - /'
@@ -122,21 +122,36 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
122122
fi
123123

124124
if [ "$has_pending_checks" = true ] || [ "$all_checks_pass" = true ]; then
125-
# Check if PR is up-to-date with base branch
126-
merge_status=$(gh pr view "$pr_number" -R "$REPO" --json mergeStateStatus -q '.mergeStateStatus')
127-
125+
# Check if PR is draft and whether it is up-to-date with base branch
126+
pr_merge_info=$(gh pr view "$pr_number" -R "$REPO" --json isDraft,mergeStateStatus)
127+
is_draft=$(echo "$pr_merge_info" | jq -r '.isDraft')
128+
merge_status=$(echo "$pr_merge_info" | jq -r '.mergeStateStatus')
129+
130+
if [ "$is_draft" = "true" ]; then
131+
echo " ⚠️ PR #$pr_number is a draft PR; skipping merge"
132+
continue
133+
fi
134+
128135
if [ "$merge_status" != "CLEAN" ]; then
129136
echo " ⚠️ PR #$pr_number is not up to date (status: $merge_status)"
130137
# Enable auto-merge to merge once checks pass
131138
echo " ✅ Enabling auto-merge (squash strategy) for PR #$pr_number"
132-
gh pr merge "$pr_number" -R "$REPO" --auto --squash
133-
echo " ✅ Auto-merge enabled for PR #$pr_number"
139+
if gh pr merge "$pr_number" -R "$REPO" --auto --squash; then
140+
echo " ✅ Auto-merge enabled for PR #$pr_number"
141+
else
142+
echo " ⚠️ Failed to enable auto-merge for PR #$pr_number; continuing to next PR"
143+
continue
144+
fi
134145
else
135146
echo " ✅ PR #$pr_number is up to date with base branch"
136147
# PR is already clean/mergeable - merge directly instead of enabling auto-merge
137148
echo " ✅ Merging PR #$pr_number directly (squash strategy)"
138-
gh pr merge "$pr_number" -R "$REPO" --squash
139-
echo " ✅ PR #$pr_number merged successfully"
149+
if gh pr merge "$pr_number" -R "$REPO" --squash; then
150+
echo " ✅ PR #$pr_number merged successfully"
151+
else
152+
echo " ⚠️ Failed to merge PR #$pr_number; continuing to next PR"
153+
continue
154+
fi
140155
fi
141156
fi
142157

0 commit comments

Comments
 (0)