Skip to content

Commit 2794a5f

Browse files
committed
Prepare to conditionally auto-approve dependabot PRs
We want to set up a flow to to auto-approve some dependabot PRs. We're having trouble testing it locally so we want to merge this version which does not actually approve PRs, but simply tells us whether it would approve them.
1 parent c2e621e commit 2794a5f

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, an dthe update is a patch version
17+
if: "!contains(steps.metadata.outputs.package-ecosystem, 'npm') && steps.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 echo "This would approve the PR"
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)