WIP Python package for interacting with Bitbucket Cloud's API.
You'll need three items:
- EMAIL: The email address used to interact with Bitbucket.
- PASSWORD: An API key used to authenticate with Bitbucket.
- API_ENDPOINT: ex https://api.bitbucket.org/2.0
Interact with the repository API
import bitbucket
api = bitbucket.API(WORKSPACE, EMAIL, PASSWORD)
repository = api.get_repository(REPOSITORY_NAME)
branches = repository.branches()
for branch in branches:
print(branch.name)
commit = next(branch.commits)
feature_branch = repository.branch('feature_branch_name')
commits = [
commit
for commit in feature_branch.commits({'exclude': 'master', 'pagelen': 100})
]
print(f"feature_branch_name is {len(commits)} commits ahead of master")
tag = repository.tag('1.0.0')
pipelines = list(api.get_pipelines(
'REPO_SLUG',
{
'target.branch':'BRANCH_NAME',
'sort': '-created_on',
'pagelen':20}))