A Pharo client for the Bitbucket Cloud REST API
If you are looking for a client targeting Bitbucket Server instead, check out: Bitbucket-Pharo-API.
Metacello new
githubUser: 'Evref-BL' project: 'BitbucketCloud-Pharo-API' commitish: 'main' path: 'src';
baseline: 'BitbucketCloudPharoAPI';
onConflict: [ :ex | ex useIncoming ];
load spec
baseline: 'BitbucketCloudPharoAPI' with: [
spec repository: 'github://Evref-BL/BitbucketCloud-Pharo-API:main'
]To start using the API, create a BitbucketCloudApi client instance. The API supports two authentication methods: access token or API token (with username).
bitbucketCloudApi := BitbucketCloudApi new
host: 'api.bitbucket.org';
accessToken: '<your-access-token>'.bitbucketCloudApi := BitbucketCloudApi new
host: 'api.bitbucket.org';
username: '<your-email>';
apiToken: '<your-api-token>'.The API provides different resource classes to interact with different entities in Bitbucket. These resources include:
- pullRequests
- refs
- repositories
- source
Each resource provides methods for interacting with the corresponding Bitbucket resource. You can access them like this:
bitbucketCloudApi repositories <method>Here are a few examples of how to interact with the API:
Fetch a pull request by ID within a repository and workspace:
| pullRequest |
pullRequest := bitbucketCloudApi pullRequests get: <pullRequestId> inRepository: '<repoSlug>' ofWorkspace: '<workspace>'.Retrieve files/directories in a repository branch with parameters (e.g., depth):
| commits params |
params := {
'max_depth' -> '10'
} asDictionary.
bitbucketCloudApi repositories getFileOrDirectory: '' fromCommit: '<branchName>' inRepository: '<repoSlug>' ofWorkspace: '<workspace>' withParams: params.Create a commit on a branch (only works with API token authentication):
| commits params |
commit := BitbucketCloudSourceCommit new
message: 'Update README';
branch: 'dev';
addFile: 'README.md' withNewContent: 'This is my updated README content.'.
bitbucketCloudApi source createCommit: commit inRepository: '<repoSlug>' ofWorkspace: '<workspace>'.