Last active
July 23, 2019 06:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if [[ ${REPO_ORIGIN} == "[email protected]"* ]] ;
この1行のyour-github-enterprise.com
は$GHE_URL
から取る方がよさそうに見えます👀