bitbucket Package¶
bitbucket
Package¶
Bitbucket has a REST API publicly available, this package provide methods to interact with it. It allows you to access repositories and perform various actions on them.
Various usages :
from bitbucket.bitbucket import Bitbucket
# Access a public repository
bb = Bitbucket(USERNAME, repo_name_or_slug="public_repository")
# Access a private repository
bb = Bitbucket(USERNAME, PASSWORD, repo_name_or_slug="private_repository")
# Access a private repository through oauth
bb = Bitbucket(USERNAME, repo_name_or_slug="public_repository")
bb.authorize(CONSUMER_KEY, CONSUMER_SECRET, 'http://localhost/')
# Access your working repository
success, result = bb.repository.get()
# Create a repository, and define it as your working repository
success, result = bb.repository.create("repository_slug")
bb.repo_slug = "repository_slug"
# Update your working repository
success, result = bb.repository.update(description='new description')
# Delete a repository
success, result = bb.repository.delete("repository_slug")
# Download a repository as an archive
success, archive_path = bb.repository.archive()
# Access user informations
success, result = bb.get_user(username=USERNAME)
# Access tags and branches
success, result = bb.get_tags()
success, result = bb.get_branches()
# Access, create, update or delete a service (hook)
success, result = bb.service.get(service_id=SERVICE_ID)
success, result = bb.service.create(service=u'POST', URL='http://httpbin.org/')
success, result = bb.service.update(service_id=SERVICE_ID, URL='http://google.com')
success, result = bb.service.delete(service_id=SERVICE_ID)
# Access, create or delete an SSH key
success, result = bb.ssh.get(key_id=SSH_ID)
success, result = bb.ssh.create(key=r'ssh-rsa a1b2c3d4e5', label=u'my key')
success, result = bb.ssh.delete(key_id=SSH_ID)
# Access, create, update or delete an issue
success, result = bb.issue.get(issue_id=ISSUE_ID)
success, result = bb.issue.create(
title=u'Issue title',
content=u'Issue content',
responsible=bb.username,
status=u'new',
kind=u'bug')
success, result = bb.issue.update(issue_id=ISSUE_ID, content='New content')
success, result = bb.issue.delete(issue_id=ISSUE_ID)
# Access, create, update or delete an issue comment
success, result = bb.issue.comment.get(comment_id=COMMENT_ID)
success, result = bb.issue.comment.create(content='Content')
success, result = bb.issue.comment.update(
comment_id=COMMENT_ID,
content='New content')
success, result = bb.issue.comment.delete(comment_id=COMMENT_ID)
Bitbucket
Module¶
-
class
bitbucket.bitbucket.
Bitbucket
(username='', password='', repo_name_or_slug='')[source]¶ This class lets you interact with the bitbucket public API.
-
auth
¶ Return credentials for current Bitbucket user.
Call this with your consumer key, secret and callback URL, to generate a token for verification.
-
dispatch
(method, url, auth=None, params=None, **kwargs)[source]¶ Send HTTP request, with given method, credentials and data to the given URL, and return the success and the result on success.
-
finalize_oauth
(access_token, access_token_secret)[source]¶ Called internally once auth process is complete.
Get a single repository on Bitbucket and return its tags.
-
get_user
(username=None)[source]¶ Returns user informations. If username is not defined, tries to return own informations.
-
password
¶ Return your repository’s password.
-
repo_slug
¶ Return your repository’s slug name.
-
username
¶ Return your repository’s username.
-
issue
Module¶
-
class
bitbucket.issue.
Issue
(bitbucket, issue_id=None)[source]¶ This class provide issue-related methods to Bitbucket objects.
-
create
(repo_slug=None, **kwargs)[source]¶ Add an issue to one of your repositories. Each issue require a different set of attributes, you can pass them as keyword arguments (attributename=’attributevalue’). Attributes are:
- title: The title of the new issue.
- content: The content of the new issue.
- component: The component associated with the issue.
- milestone: The milestone associated with the issue.
- version: The version associated with the issue.
- responsible: The username of the person responsible for the issue.
- status: The status of the issue (new, open, resolved, on hold, invalid, duplicate, or wontfix).
- kind: The kind of issue (bug, enhancement, or proposal).
-
issue_id
¶ Your repository slug name.
-
update
(issue_id, repo_slug=None, **kwargs)[source]¶ Update an issue to one of your repositories. Each issue require a different set of attributes, you can pass them as keyword arguments (attributename=’attributevalue’). Attributes are:
- title: The title of the new issue.
- content: The content of the new issue.
- component: The component associated with the issue.
- milestone: The milestone associated with the issue.
- version: The version associated with the issue.
- responsible: The username of the person responsible for the issue.
- status: The status of the issue (new, open, resolved, on hold, invalid, duplicate, or wontfix).
- kind: The kind of issue (bug, enhancement, or proposal).
-
issue_comment
Module¶
-
class
bitbucket.issue_comment.
IssueComment
(issue)[source]¶ This class provide issue’s comments related methods to Bitbucket objects.
-
create
(issue_id=None, repo_slug=None, **kwargs)[source]¶ Add an issue comment to one of your repositories. Each issue comment require only the content data field the system autopopulate the rest.
-
repository
Module¶
-
class
bitbucket.repository.
Repository
(bitbucket)[source]¶ This class provide repository-related methods to Bitbucket objects.
-
archive
(repo_slug=None, format='zip', prefix='')[source]¶ Get one of your repositories and compress it as an archive. Return the path of the archive.
format parameter is curently not supported.
-
create
(repo_name, scm='git', private=True, **kwargs)[source]¶ Creates a new repository on own Bitbucket account and return it.
-
delete
(repo_slug=None)[source]¶ Delete a repository on own Bitbucket account. Please use with caution as there is NO confimation and NO undo.
-
service
Module¶
-
class
bitbucket.service.
Service
(bitbucket)[source]¶ This class provide services-related methods to Bitbucket objects.
-
create
(service, repo_slug=None, **kwargs)[source]¶ Add a service (hook) to one of your repositories. Each type of service require a different set of additionnal fields, you can pass them as keyword arguments (fieldname=’fieldvalue’).
-