Skip to content

Commit 630de98

Browse files
committed
Conditionally auto-approve dependabot PRs
We want to set up a flow to to auto-approve some dependabot PRs. PRs will only be approved if: - they are not `npm` updates, and - the update is only a version patch
1 parent c2e621e commit 630de98

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Dependabot auto-approve
2+
on: pull_request
3+
permissions:
4+
pull-requests: write
5+
jobs:
6+
dependabot:
7+
runs-on: ubuntu-latest
8+
# Checking the author will prevent your Action run failing on non-Dependabot PRs
9+
if: github.event.pull_request.user.login == 'dependabot[bot]'
10+
steps:
11+
- name: Dependabot metadata
12+
id: dependabot-metadata
13+
uses: dependabot/fetch-metadata@v2
14+
- uses: actions/checkout@v4
15+
- name: Approve a PR if not already approved
16+
# as long as it's not a npm PR, and the update is a patch version
17+
if: "!contains(steps.dependabot-metadata.outputs.package-ecosystem, 'npm') && steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch'"
18+
run: |
19+
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
20+
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
21+
then gh pr review --approve "$PR_URL"
22+
else echo "PR already approved, skipping additional approvals to minimize emails/notification noise.";
23+
fi
24+
env:
25+
PR_URL: ${{github.event.pull_request.html_url}}
26+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)