Last active
February 9, 2022 11:55
-
-
Save ianwremmel/2fcee01a345c799283295da6d529c901 to your computer and use it in GitHub Desktop.
merge-dependabot-pr.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script creates a consolidate Pull Request for all outstanding dependabot | |
# Pull Requests. | |
# | |
# Motivation: Sometimes, dependabot opens a large number of PRs that all need to | |
# be merged. Each time one merges, it causes the rest to be out of date, making | |
# it a slow, manual process of clicking upate, waiting for ci, then clicking | |
# merge for each subsequent PR. | |
# | |
# Usage: | |
# | |
# ```bash | |
# cd MY_GIT_REPO | |
# merge-dependabot-prs.sh | |
# ``` | |
# | |
# TODO: Only merge PRs with a successful CI status | |
# | |
# Maintainer: [Ian Remmel](https://github.com/ianwremmel) | |
# | |
# Contribution: This gist will be updated based on feedback in the comments, as | |
# appropriate | |
# | |
# License: MIT | |
# | |
# Copyright: Ian Remmel © 2018 until at least now | |
# | |
set -euo pipefail | |
if ! command -v hub >/dev/null 2>&1; then | |
echo | |
echo "This script requires hub" | |
echo "https://hub.github.com/" | |
echo | |
exit 1 | |
fi | |
if ! command -v http >/dev/null 2>&1; then | |
echo | |
echo "This script requires httpie" | |
echo "https://httpie.org/" | |
echo | |
exit 1 | |
fi | |
if ! command -v jq >/dev/null 2>&1; then | |
echo | |
echo "This script requires jq" | |
echo "https://stedolan.github.io/jq/" | |
echo | |
exit 1 | |
fi | |
echo "Making sure master is update to date with origin/master" | |
git checkout master | |
git pull --rebase | |
echo "Checking out new branch" | |
git checkout -b "merges-$(date +%s)" | |
echo "Retrieving dependabot branches from GitHub and merging into current branch" | |
http "$(git remote -v | awk -F"[ :/.]" '/origin.*fetch/{print "https://api.github.com/repos/" $3 "/" $4 "/issues"}')" labels==dependencies | jq .[].html_url | xargs -n 1 hub merge | |
echo "Pushing current branch to origin" | |
git push -u origin "$(git branch | awk '/\* /{print $2}')" | |
echo "Opening Pull Request" | |
hub pull-request -m 'Consolidated dependabot merges' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment