Created
September 18, 2013 15:23
-
-
Save toddself/6610784 to your computer and use it in GitHub Desktop.
Command line pull-request generation with pivotal and github integration.
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
#/bin/sh | |
PIVOTAL_ACCESS= | |
PIVOTAL_PROJECT_ID= | |
GITHUB_ACCESS= | |
DEFAULT_BRANCH=development | |
TO_REPO_OWNER=CondeNast | |
FROM_REPO_OWNER=CondeNast | |
function pr (){ | |
ARGS=("$@") | |
# do we need help? | |
if [ "${ARGS[0]}" == "-h" ] | |
then | |
echo "pr MESSAGE PIVOTAL_TICKET_ID" | |
return 0 | |
fi | |
# are we in a git repo? | |
GIT_BRANCH=$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p') | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
echo "You're not in a git repo..." | |
return 0 | |
fi | |
GIT_REPO_NAME=$(basename `git rev-parse --show-toplevel`) | |
# make the pull request and get the ID | |
PULL_URL=$(git pull-request "${ARGS[0]}" -b $TO_REPO_OWNER:$DEFAULT_BRANCH -h $FROM_REPO_OWNER:$GIT_BRANCH) | |
echo "Pull request made: $PULL_URL" | |
PULL_ID=$(echo $PULL_URL | cut -d/ -f 7) | |
# do we have a pivotal ticket o deal with? | |
if [ -n ${ARGS[1]} ] | |
then | |
echo "Updating Pivotal..." | |
# UPDATE PIVOTAL... | |
PIVOTAL_RESPONSE=$(curl -s -H "X-TrackerToken: $PIVOTAL_ACCESS" -X POST -H "Content-type: application/xml" -d "<note><text>$PULL_URL</text></note>" https://www.pivotaltracker.com/services/v3/projects/$PIVOTAL_PROJECT_ID/stories/${ARGS[1]}/notes) | |
echo "Updating Github..." | |
# UPDATE GITHUB... | |
PAYLOAD="{\"body\": \"https://www.pivotaltracker.com/story/show/${ARGS[1]}\"}" | |
GIT_URL="https://api.github.com/repos/condenast/$GIT_REPO_NAME/pulls/$PULL_ID" | |
GIT_RESPONSE=$(curl -s -X PATCH -H "Content-type: application/json" -H "Authorization: token $GITHUB_ACCESS" -d "$PAYLOAD" $GIT_URL) | |
fi | |
echo "Done" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment