Scripting Dependabot PR Merges

Install the gh command line github client, and login to your account:

brew install gh
gh auth login

This following scripts also require you to have jq installed for json filtering/manipulation. brew install jq if you don’t already have it.

Then, download a list of all your github projects

gh repo list <username or org> --no-archived -L 200 --source | cut -f 1 > github_projects.txt

You can add a --private flag to only return private repos.

Fetch a list of all the Dependabot opened prs across all your projects, in ascending PR order:

cat github_projects.txt |
PAGER= xargs -n 1 -I "{}" gh pr list -l dependencies -R "{}" --json number,headRepository |
jq -s '.' |
jq '. | map(select(length > 0)) | map(.[])' |
jq -r 'map("gh pr merge " + (.number | tostring) + " -R \"$GITHUB_ACCOUNT/" + + "\" -m") | .[]' |
tac >
GITHUB_ACCOUNT=<your gh username or org> bash