-
-
Save mercurieus/dc38b644046a93737197567e879c6c80 to your computer and use it in GitHub Desktop.
Bitbucket Pipelines - Create Pull Request (PR) with default reviewers
This file contains hidden or 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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment