Create a gist now

Instantly share code, notes, and snippets.

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