Skip to content

Instantly share code, notes, and snippets.

@dcosson
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcosson/9591444 to your computer and use it in GitHub Desktop.
Save dcosson/9591444 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Uses github's hub command line tool and r10kdiff gem to open a pull request
# for a repository containing a Puppetfile used by r10k.
#
# Assumes it should be from the current branch <Puppet Environment Name> in a
# fork to the same branch upstream (since you can't use feature branches in the
# same repository with r10k as it might deploy them as environments)
#
if [ $# -ne 2 ] ;
then
echo "Usage: open-r10k-repo-pull-request <github-user> <upstream-user-or-org>"
exit 1
else
github_username=$1
upstream_github_username=$2
fi
# Make sure we're in a git repo
git status >/dev/null 2>&1 || ( echo "ERROR: Need to run from a git repo" && exit 1 )
branchname="$(basename $(git symbolic-ref HEAD))"
tmpfile="./puppet-environments-pr-tmp.txt"
# PR name defaults to last commit msg like when opening from the web UI
echo -e "$(git log $branchname -n 1 --pretty=format:%s)\n\n" > $tmpfile
r10kdiff --urls origin/$branchname $branchname >> $tmpfile
"${EDITOR:-vi}" $tmpfile
hub pull-request -F $tmpfile -b $upstream_github_username:$branchname -h $github_username:$branchname
rm $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment