Use BitBucket's API to automatically create and merge pull requests. This is useful for triggering build processes from CMS webhooks.
Required arguments:
-s | --source
Source git branch to create pull request from.-d | --destination
Destination git branch to merge pull request to.
Optional arguments:
-u | --user
BitBucket username. If not set, uses BITBUCKET_AUTOMERGE_USER.-p | --password
BitBucket user password. If not set, uses BITBUCKET_AUTOMERGE_PASS.--repo-owner
The repository owner. If not set, uses BITBUCKET_REPO_OWNER.--repo-slug
The slug of the repository. If not set, uses BITBUCKET_REPO_SLUG.--version
Display the version of this script
Requirements:
curl
for making network requests with options.jq
for reading JSON data.
Create and automatically merge a pull request from AUTO_MERGE to qa:
# Merge master into develop
./script.sh -s AUTO_MERGE -d qa
All options:
script.sh -s AUTO_MERGE -d qa -u sunsbot -p xyzxyz --repo-owner NBAFrontEndDev --repo-slug nba-teams-static-suns
To use, create a branch in your repository called "AUTO_MERGE", create a file on that branch called auto_merge. Setup your user or a new user with write/merge access to the repository. Generate an app password for that user https://bitbucket.org/account/settings/app-passwords/
Create a post request
curl --location --request POST 'http://localhost:8080/' \
--header 'Authorization: Bearer APP_PASSWORD' \
--header 'Content-Type: application/json' \
--data-raw '{
"RepoSourceBranch" : "AUTO_MERGE",
"RepoTargetBranch" : "qa",
"RepoName" : "nba-teams-static-suns",
"RepoUser" : "NBAFrontEndDev",
"BitbucketUser" : "sunsbot"
}'
- Edit invoke.go or bitbucket-auto-merge.sh
- docker build . (when complete, this outputs an image hash like sha:01010101....., copy for next line)
- docker run -dp 8080:8080 -it sha:01010101.....
- Run post request in to localhost
Authentication: Bearer [bitbucket password] Post Body
{
"RepoSourceBranch" : "AUTO_MERGE",
"RepoTargetBranch" : "qa",
"RepoName" : "nba-teams-static-suns",
"RepoUser" : "NBAFrontEndDev",
"BitbucketUser" : "sunsbot"
}
This project auto deploys on a merge or push to the master
branch, the app url is https://bitbucket-auto-merge-m3rbwjxm5q-uc.a.run.app/ the project it deploys to is zesty-dev