Skip to content

Instantly share code, notes, and snippets.

@Kornel
Last active September 30, 2016 07:50
Show Gist options
  • Save Kornel/28d39465cc77908c1829efad529de6bf to your computer and use it in GitHub Desktop.
Save Kornel/28d39465cc77908c1829efad529de6bf to your computer and use it in GitHub Desktop.
Push to bitbucket (stash) and create pull-request
#!/bin/sh
REMOTE_BRANCH=$1
if [[ -z "${REMOTE_BRANCH}" ]]
then
REMOTE_BRANCH="develop"
fi
USER=`whoami`
PROJECT=`git remote -v | grep push | awk -F"/" ' { print $4 } '`
REPO=`git remote -v | grep push | awk -F"/" ' { print $5 } ' | sed 's/\.git.*//'`
BRANCH=`git rev-parse --abbrev-ref HEAD`
TITLE=$BRANCH
URL="https://stash.allegrogroup.com/rest/api/1.0/projects/$PROJECT/repos/$REPO/pull-requests"
BODY='{
"title": "'$TITLE'",
"description": "'$TITLE'",
"state": "OPEN",
"open": true,
"closed": false,
"fromRef": {
"id": "refs/heads/'$BRANCH'",
"repository": {
"slug": "'$REPO'",
"name": null,
"project": {
"key": "'$PROJECT'"
}
}
},
"toRef": {
"id": "refs/heads/'$REMOTE_BRANCH'",
"repository": {
"slug": "'$REPO'",
"name": null,
"project": {
"key": "'$PROJECT'"
}
}
},
"locked": false
}'
git push && curl -H 'Content-Type: application/json ' -XPOST -u $USER -d "$BODY" $URL | jq '.links.self[].href'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment