Repositories, pull requests, comments, reviewers and build statuses on Bitbucket
Data Center / Server, through REST API 1.0 (/rest/api/1.0, plus
/rest/build-status/1.0 and /rest/default-reviewers/1.0). Verification level:
unit.
Supported versions: The oldest Bitbucket Data Center version toil supports hasn’t been established. toil calls REST API 1.0 with an HTTP access token sent as a Bearer header. No release has been verified yet.
Credential
A Bitbucket HTTP access token: in Bitbucket, your profile picture → Manage
account → HTTP access tokens → Create token. Give it repository write (or admin, for
repo create) permission if you’ll use the write commands. toil sends it as
Authorization: Bearer <token>. There is no username, password or browser login.
Configuration
| Key | Env var | Required | Meaning |
|---|---|---|---|
baseUrl | TOIL_BITBUCKET_BASE_URL | yes | Bitbucket server root, e.g. https://bitbucket.imagile.dev (keep any context path) |
pat | TOIL_BITBUCKET_PAT | yes | HTTP access token |
project | TOIL_BITBUCKET_PROJECT | no | Default project key, when --project isn’t given |
repo | TOIL_BITBUCKET_REPO | no | Default repository slug, when --repo isn’t given |
targetBranch | TOIL_BITBUCKET_TARGET_BRANCH | no | Default target branch for pr create (main when unset) |
writes | TOIL_BITBUCKET_WRITES | no | true lets write commands run (with --allow-write) |
There’s no CI fallback variable.
Environment variables (CI, or a one-off shell):
export TOIL_BITBUCKET_BASE_URL=https://bitbucket.imagile.dev
export TOIL_BITBUCKET_PAT=<your HTTP access token>
Or ~/.toil/config.json, with project, repo and targetBranch usually set once
under defaults.bitbucket:
{
"version": 2,
"connections": {
"corp-bitbucket": { "area": "bitbucket", "baseUrl": "https://bitbucket.imagile.dev", "writes": true }
},
"defaults": { "bitbucket": { "connection": "corp-bitbucket", "project": "PROJ", "repo": "imagile-api", "targetBranch": "develop" } }
}
The token never goes in this file; a plaintext one there is refused with
CONFIG_INVALID. Run toil connections add corp-bitbucket --area bitbucket (or
toil connections login corp-bitbucket for an existing connection) to keep it in the
OS credential store, or set TOIL_BITBUCKET_PAT.
Where a command acts
--project <key> and --repo <slug> are group flags, accepted before or after the
command (toil bitbucket --project PROJ pr list, or
toil bitbucket pr create --project ~jdoe --repo scratch ... for a personal
repository). Without them, toil reads them from the first of the workspace’s remotes
on the connection’s host, of any name, trying origin first (git@<host>:PROJ/repo.git or
https://<host>/scm/PROJ/repo.git; ssh:// URLs and HTTPS with a user name aren’t
recognised), so a fork whose Bitbucket remote is upstream works too, then the connection’s
project and repo settings. repo create and pr create-many need
only a project; every other command needs both, and fails with “Could not determine
Bitbucket project/repo” when either is missing. meta.context says where each came
from.
Pull request and comment ids are read as whole numbers from the start of the text:
12abc is 12, and abc is sent as NaN.
Commands
Every command is toil bitbucket <resource> <action> [ids...], and its MCP tool is the
path with underscores (bitbucket_pr_get, bitbucket_pr_comment_inline).
Repositories:
repo create: Create a git repository in a project (--name,--description).repo default-reviewers: The repository’s default-reviewer conditions.
Pull requests (<id> is the pull request id):
pr list: List pull requests, every page.--stateisOPEN(default),MERGED,DECLINEDorALL;--authorand--reviewertake usernames;--created-after(inclusive) and--created-before(exclusive) take ISO 8601 dates and filter after fetching. A date alone is UTC midnight; a date-time without a zone is local time.pr get <id>: Get a pull request.pr create: Create a pull request (--title,--source,--target,--description,--reviewers a,b). Without--reviewers, Bitbucket’s default-reviewer conditions apply.pr create-many: Promote--fromto--toin every repository in--repos a,b, one at a time, skipping repositories with nothing to promote. Each one reportscreated,nothing_to_promoteorerror, with counts insummary. The command succeeds even when every repository failed, so checksummary.error; that case also carries aBITBUCKET_ALL_FAILEDwarning inmeta.warnings. Its time limit is 30 minutes rather than 2, so a long batch still reports every repository. The title defaults toPromote <from> to <to>.pr update <id>: Change--title,--descriptionor--reviewers(which replaces the whole list). Anything not given is resent as it is now, so nothing is cleared.pr merge <id>: Merge at the current version.--strategyis sent as Bitbucket’s merge strategy id (squash,ff; Bitbucket calls a merge commitno-ff).--delete-branchsets Bitbucket’sautoSubjectand doesn’t delete the branch; the merge still succeeds, with aBITBUCKET_BRANCH_NOT_DELETEDwarning.pr decline <id>: Decline at the current version.pr current: The open pull request whose source branch is the workspace’s current git branch, ornull.toil git current-pris the same command. The branch is read from.git(no git needed). With no Bitbucket connection, or one missing itspat, it succeeds with{ "message": "Requires Bitbucket config. ..." }(the latter with aCONFIG_INCOMPLETEwarning).
Comments:
pr comments <id>: Comments, oldest first, replies flattened in withparentId.--no-with-repliesreturns top-level comments only (replies stay nested undercomments),--inline-onlyonly file comments,--general-onlyonly general ones.pr comment <id>: A general comment (--body).pr comment-inline <id>: A comment on a line (--file,--line,--body,--line-type ADDED|REMOVED|CONTEXT, defaultADDED). The line is anchored to the new version of the file.pr reply <id> <comment-id>: Reply to a comment (--body).pr resolve <id> <comment-id>: Resolve a thread by its root comment, at--comment-version(default0;pr commentsreports each comment’sversion). Returns{ "resolved": true }.pr delete-comment <id> <comment-id>: Delete a comment at--comment-version(default0). Returns{ "deleted": true }. CLI only: deletes are never exposed through MCP.
Review and builds:
pr diff <id>:data.diffis Bitbucket’s JSON diff structure as a string, not unified diff text.--filelimits it to one path;--context-linessets the context.pr files <id>: The changed paths, from one request of up to 1000 changes. An entry that Bitbucket returns as a path object comes back as that object in a JSON string.pr approve <id>,pr unapprove <id>: Approve, or withdraw approval, as the token’s user.pr needs-work <id>: Mark needs-work as the token’s user, adding them as a reviewer first when they aren’t one. That addition stays if the status change then fails.pr reviewers <id>: The pull request’s reviewers and their status.pr add-reviewer <id>: Add--useras a reviewer.pr builds <id>: Build statuses of the pull request’s newest commit.commit status <commit>: Build statuses of a commit. It still needs a project and repo, though it doesn’t use them.
pr builds and commit status return one page of statuses, at Bitbucket’s default
size (25).
Write commands need writes: true on the connection and --allow-write on the call.
toil bitbucket --project PROJ --repo imagile-api pr list --state OPEN --author jdoe
toil bitbucket pr get 42
toil bitbucket pr create --title "Add retries" --source feature/retries --allow-write
toil bitbucket pr comments 42 --no-with-replies
Checking a dossier
check-dossier checks the call’s dossier: each project key it names (project, per repo or not, and projects) exists, and each repository (repo) in its project. It’s toil bitbucket check-dossier (--dossier <name|file>, or the dossier the folder resolves to), and it returns { dossier, connection, env, ok, checked, checks, unchecked }, one check per value with its key path. The CLI exits 1 when one is missing. A failure other than not-found (a bad token, an unreachable host) fails the command. Read only.
Settings at a glance
-
baseUrlrequiredBitbucket server root, e.g. https://bitbucket.imagile.dev
TOIL_BITBUCKET_BASE_URL -
patrequired secretHTTP access token
TOIL_BITBUCKET_PAT -
projectDefault project key
TOIL_BITBUCKET_PROJECT -
repoDefault repository slug
TOIL_BITBUCKET_REPO -
targetBranchDefault target branch for pr create (main when unset)
TOIL_BITBUCKET_TARGET_BRANCH
Commands at a glance
toil bitbucketrepo createwriteCreate a new repository in a project
toil bitbucketpr listList pull requests
toil bitbucketpr getGet a pull request by ID
toil bitbucketpr createwriteCreate a pull request
toil bitbucketpr create-manywriteCreate pull requests for multiple repositories in a project
toil bitbucketpr updatewriteUpdate a pull request
toil bitbucketpr mergewriteMerge a pull request
toil bitbucketpr declinewriteDecline a pull request
toil bitbucketpr currentalsotoil git current-prFind the open PR for the current branch
toil bitbucketpr commentsList comments on a pull request (includes threaded replies by default)
toil bitbucketpr commentwriteAdd a comment to a pull request
toil bitbucketpr comment-inlinewriteAdd an inline comment to a file in a pull request
toil bitbucketpr replywriteReply to a comment on a pull request
toil bitbucketpr resolvewriteResolve a comment thread on a pull request (use the root comment ID, not a reply)
toil bitbucketpr delete-commentwriteCLI onlyDelete a comment on a pull request
toil bitbucketpr diffGet unified diff for a pull request
toil bitbucketpr filesList files changed in a pull request
toil bitbucketpr approvewriteApprove a pull request
toil bitbucketpr unapprovewriteRemove approval from a pull request
toil bitbucketpr needs-workwriteMark a pull request as needs-work
toil bitbucketpr reviewersList reviewers of a pull request
toil bitbucketrepo default-reviewersList the default-reviewer conditions configured for a repository
toil bitbucketpr add-reviewerwriteAdd a reviewer to a pull request
toil bitbucketpr buildsList build statuses for a pull request
toil bitbucketcommit statusGet build status for a commit SHA
toil bitbucketcheck-dossierCheck the call's dossier against Bitbucket: its projects and repositories exist