Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to backport a PR to branch (used mainly for working with the ownCloud documentation)
#!/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
You can’t perform that action at this time.