Skip to content

Instantly share code, notes, and snippets.

@wirths
Created December 5, 2019 16:56
Show Gist options
  • Save wirths/2a3952ec681bee95e551c4e40025793b to your computer and use it in GitHub Desktop.
Save wirths/2a3952ec681bee95e551c4e40025793b to your computer and use it in GitHub Desktop.
Bitbucket Pipelines - Create Pull Request (PR) with default reviewers
image: node:12
definitions:
steps:
- step: &create-pr
name: Create Pull Request
caches:
- node
script:
- apt-get update
- apt-get -y install curl jq
- '[[ "$BITBUCKET_BRANCH" == feature/* || $BITBUCKET_BRANCH == bugfix/* ]] && export DESTINATION_BRANCH="develop" || export DESTINATION_BRANCH="master"'
- '[[ "$BITBUCKET_BRANCH" == "develop" ]] && export CLOSE_ME=false || export CLOSE_ME=true'
- >
export BB_TOKEN=$(curl -s -S -f -X POST -u "${BB_AUTH_STRING}" \
https://bitbucket.org/site/oauth2/access_token \
-d grant_type=client_credentials -d scopes="repository" | jq --raw-output '.access_token')
- >
export DEFAULT_REVIEWERS=$(curl https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/default-reviewers \
-s -S -f -X GET \
-H "Authorization: Bearer ${BB_TOKEN}" | jq '.values' | jq 'map({uuid})' )
- >
curl https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/pullrequests \
-s -S -f -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${BB_TOKEN}" \
-d '{
"title": "Merge in '"${BITBUCKET_BRANCH}"'",
"description": "Automated PR creation process :-)",
"source": {
"branch": {
"name": "'"${BITBUCKET_BRANCH}"'"
}
},
"destination": {
"branch": {
"name": "'"${DESTINATION_BRANCH}"'"
}
},
"close_source_branch": '"${CLOSE_ME}"',
"reviewers": '"${DEFAULT_REVIEWERS}"'
}'
pipelines:
branches:
'{bugfix/*,feature/*}':
- step: *create-pr
'{develop,release/*,hotfix/*}':
- step: *create-pr
@artitambe26
Copy link

What is bit bucket repo slug exactly?

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