Skip to content

Commit bece035

Browse files
committed
fixed dependabot auto pr merge workflow
1 parent eabb93f commit bece035

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,36 @@ jobs:
1414
runs-on: ubuntu-latest
1515
if: github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch'
1616
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
1720
- name: Approve and Auto-Merge PRs
1821
run: |
1922
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
20-
echo "Batch processing all open Dependabot PRs..."
23+
echo "Batch processing all open Dependabot PRs for repo: $GH_REPO..."
2124
# Get list of open PR numbers from dependabot
22-
prs=$(gh pr list --app dependabot --state open --json number -q '.[].number')
23-
if [ -z "$prs" ]; then
24-
prs=$(gh pr list --author "app/dependabot" --state open --json number -q '.[].number')
25-
fi
25+
prs=$(gh pr list --state open --json number,author -q '.[] | select(.author.login | contains("dependabot")) | .number')
26+
2627
if [ -z "$prs" ]; then
27-
prs=$(gh pr list --state open --json number,author -q '.[] | select(.author.login | contains("dependabot")) | .number')
28+
echo "No open Dependabot PRs found."
29+
exit 0
2830
fi
2931
32+
echo "Found open Dependabot PRs: $prs"
33+
3034
for pr in $prs; do
31-
echo "Reviewing and approving PR #$pr..."
32-
gh pr review "$pr" --approve || true
33-
echo "Enabling auto-merge on PR #$pr..."
34-
gh pr merge "$pr" --auto --squash || gh pr merge "$pr" --squash || true
35+
echo "Processing PR #$pr..."
36+
# Approve the PR
37+
gh pr review "$pr" --approve || echo "Could not approve PR #$pr (might already be approved)"
38+
39+
# Try auto-merge with squash, or direct squash merge if eligible
40+
gh pr merge "$pr" --auto --squash || gh pr merge "$pr" --squash || echo "PR #$pr cannot be merged right now (checks might still be running or failing)"
3541
done
3642
else
3743
echo "Processing single PR: ${{ github.event.pull_request.html_url }}"
38-
gh pr review "${{ github.event.pull_request.html_url }}" --approve
39-
gh pr merge "${{ github.event.pull_request.html_url }}" --auto --squash || gh pr merge "${{ github.event.pull_request.html_url }}" --squash || true
44+
gh pr review "${{ github.event.pull_request.number }}" --approve || true
45+
gh pr merge "${{ github.event.pull_request.number }}" --auto --squash || gh pr merge "${{ github.event.pull_request.number }}" --squash || true
4046
fi
4147
env:
4248
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
GH_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)