Created
February 13, 2018 10:41
-
-
Save settermjd/3e44c827b5633b933dcfb7fdc9a25db2 to your computer and use it in GitHub Desktop.
Script to backport a PR to branch (used mainly for working with the ownCloud documentation)
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 | |
set -e | |
# Script to backport a PR to branch | |
# ./backport-pr.sh backportTo backportFrom prId | |
# This script requires two other tools: | |
# - github-api-tools | |
# - git-backport | |
# add your GitHub credentials | |
username= | |
password= | |
backportTo=$1 | |
backportFrom=$2 | |
prId=$3 | |
# Create a backport branch off of the latest stable branch | |
echo "Checking out backport branch: $backportTo" | |
git checkout "$backportTo" | |
echo | |
echo "Retrieving latest changes to $backportTo" | |
# TODO Handle the case where the pull fails | |
git pull | |
echo | |
echo "Creating backport branch 'backport-$backportFrom' from '$backportTo'." | |
# TODO Handle the case where the branch already exists | |
git checkout -b "backport-$backportFrom" | |
git push --set-upstream origin "backport-$backportFrom" | |
echo | |
# Cherry pick the commits from the specified PR | |
# TODO Handle the case where no commits are retrieved or the PR isn't found | |
commitList=$( github-api-tools -prId "$prId" -username "$username" -password "$password" ) | |
echo "Cherry picking these commits $commitList onto backport-$backportFrom." | |
# TODO Handle the case where the cherry-commit results in merge conflicts | |
git cherry-pick $commitList | |
echo "Pushing backport branch to remote." | |
# TODO Handle the case where the push fails | |
git push | |
echo | |
echo "Creating backport PR." | |
echo "It's over to you now." | |
git-backport "$backportTo" | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment