Skip to content

Instantly share code, notes, and snippets.

@prog893
Last active July 23, 2019 06:09
Show Gist options
  • Save prog893/de2f9c0de06b0ad95a013828344c161e to your computer and use it in GitHub Desktop.
Save prog893/de2f9c0de06b0ad95a013828344c161e to your computer and use it in GitHub Desktop.
pullreq: Put this to your shell profile and create pull requests in seconds
function pullreq {
CURRENT_BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2)
REPO_ORIGIN=$(git remote get-url --push origin)
GHE_URL="your-github-enterprise.com"
if [[ ${CURRENT_BRANCH_NAME} == "master" ]] ;
then
echo "You are on master branch! Doing nothing"
return
fi
if [[ ${REPO_ORIGIN} == "git@${GHE_URL}"* ]] ;
then
REPO_URL=$(echo ${REPO_ORIGIN} | sed 's/^git@'${GHE_URL}':/https:\/\/'${GHE_URL}'\//' | sed 's/\.git$//')
PR_URL="${REPO_URL}/pull/new/${CURRENT_BRANCH_NAME}"
elif [[ ${REPO_ORIGIN} == "[email protected]"* ]]; then
REPO_URL=$(echo ${REPO_ORIGIN} | sed 's/^[email protected]:/https:\/\/github.com\//' | sed 's/\.git$//')
PR_URL="${REPO_URL}/pull/new/${CURRENT_BRANCH_NAME}"
else
echo "Unknown origin: ${REPO_ORIGIN}, doing nothing"
return
fi
echo "Pushing branch ${CURRENT_BRANCH_NAME} to origin"
git push --set-upstream origin ${CURRENT_BRANCH_NAME}
echo "Opening PR creation page"
open ${PR_URL}
# above works only in macOS
}
@konojunya
Copy link

if [[ ${REPO_ORIGIN} == "[email protected]"* ]] ; この1行の your-github-enterprise.com$GHE_URL から取る方がよさそうに見えます👀

@prog893
Copy link
Author

prog893 commented Jul 18, 2019

fixed in revision 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment