Skip to content

Instantly share code, notes, and snippets.

@mkoertgen
Last active October 13, 2023 09:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkoertgen/550f7e9d15a91eaf58db6763ed455e92 to your computer and use it in GitHub Desktop.
Save mkoertgen/550f7e9d15a91eaf58db6763ed455e92 to your computer and use it in GitHub Desktop.
Accept all dependabot pull requests using GitHub CLI

Batch Accept Dependabot PRs

In case you want to automate batch accpeting Dependabot Pull Requests

GitHub

Using the GitHub CLI

Windows Batch

gh pr list --json number -q .[].number -S author:app/dependabot > prs.txt
for /f %a in (prs.txt) do (gh pr merge -d -r %a)

Linux Bash

gh pr list --json number -q .[].number -S author:app/dependabot | xargs gh pr merge -d -r

Azure DevOps

In case you are using Dependabot with Azure DevOps

Using the Azure CLI

az repos pr list --status active [--creator <build-service-dependabot>] > prs.json
jq .[].pullRequestId prs.json > prs.txt
for /f %a in (prs.txt) do (
  az repos pr update --id %a --status completed --delete-source-branch true --transition-work-items true
)

Cleanup stale remote branches

Get all remote branches (not merged yet), match dependabot-branches using ripgrep and delete

git branch -r --no-merged | rg '(dependabot/.+)' -or '$1' | xargs git push origin -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment