Skip to content

Instantly share code, notes, and snippets.

@leesio
Created March 27, 2018 08:51
Show Gist options
  • Save leesio/567b07bc813365ddca08911319507acf to your computer and use it in GitHub Desktop.
Save leesio/567b07bc813365ddca08911319507acf to your computer and use it in GitHub Desktop.
#!/bin/bash
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
URL="$2"
if [[ ! $URL = *"git@github.com"* ]]; then
exit 0
fi
REPO_PATH="$(echo $URL | sed -E 's/^.*:(.*).git.*/\1/')"
ORG="$(echo $REPO_PATH | cut -f1 -d '/')"
REPO="$(echo $REPO_PATH | cut -f2 -d '/')"
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
echo "Pull request url: https://github.com/$ORG/$REPO/compare/$BRANCH?expand=1"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment