Skip to content

Instantly share code, notes, and snippets.

@reiki4040
Created March 8, 2017 12:44
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 reiki4040/b31e1c3ea3e5bd8c414d1b3064c75981 to your computer and use it in GitHub Desktop.
Save reiki4040/b31e1c3ea3e5bd8c414d1b3064c75981 to your computer and use it in GitHub Desktop.
auto generate pull request sample.
#!/bin/bash
function usage() {
cat <<_EOB
Create Pull Request that homebrew-rnzoo for new version.
Usage:
$(basename $0) <version> <sha256hash>
_EOB
}
function err_exit() {
echo $* >&2
exit 1
}
function main() {
# TODO check version format
ver=$1
if [ -z "$ver" ]; then
err_exit "version is empty. it is required"
fi
# TODO check hex format
s256=$2
if [ -z "$s256" ]; then
err_exit "sha256 is empty. it is required"
fi
tmpdir=$(mktemp -d /tmp/genpr.XXXXXX)
echo "made" $tmpdir
echo "clone homebrew-rnzoo repo..."
tmprepo="$tmpdir/homebrew-rnzoo"
git clone git@github.com:reiki4040/homebrew-rnzoo.git $tmprepo
echo "creating version branch and editing version and sha256 hash..."
cd $tmprepo
bname="version/${ver}"
git checkout -b ${bname}
# replace version and sha256
cat rnzoo.rb | sed -e "s/version \".*\"/version \"${ver}\"/" | sed -e "s/sha256 \".*\"/sha256 \"${s256}\"/" > rnzoo.rb.new
mv rnzoo.rb.new rnzoo.rb
echo "commit..."
git commit -a -m "rnzoo version ${ver}"
if [ -z "$push_origin" ]; then
echo "commit done. if you want create pull request, then specify -p option."
exit 0
fi
echo "pushing to github..."
git push origin ${bname}
echo "creating Pull Request"
hub pull-request -m "this is test PR with hub command" -b "reiki4040:master" -h "reiki4040:${bname}"
echo "done."
echo "if you want remove temp files, please remove $tmprepo manually"
}
push_origin=""
while getopts hp OPT
do
case $OPT in
h) usage
exit 0
;;
p)
push_origin="1"
;;
*) echo "unknown option."
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
main $1 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment