Skip to content

Instantly share code, notes, and snippets.

@ericclemmons
Created April 12, 2024 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericclemmons/5adce288f14fb4e0324922c066c5f185 to your computer and use it in GitHub Desktop.
Save ericclemmons/5adce288f14fb4e0324922c066c5f185 to your computer and use it in GitHub Desktop.
# https://github.com/dependabot/fetch-metadata#enabling-auto-merge
name: Auto-merge Dependabot
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
name: 'Dependabot'
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
permissions:
# Required for auto-merge – https://github.com/dependabot/fetch-metadata?tab=readme-ov-file#enabling-auto-merge
contents: write
# Required for auto-approving – https://github.com/dependabot/fetch-metadata?tab=readme-ov-file#auto-approving
pull-requests: write
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
- name: Enable auto-merge for Dependabot PRs
# Conditionals for when it's safe. For now, all passing checks is fine.
# if: ${{contains(steps.metadata.outputs.dependency-names, 'rails') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- uses: actions/checkout@v4
- name: Approve a PR if not already approved
run: |
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
then gh pr review --approve "$PR_URL"
else echo "PR already approved, skipping additional approvals to minimize emails/notification noise.";
fi
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment