Maintainer/contributor documentation for @scr2em/bitbucket-cli. End-user docs live in
README.md.
- Node.js 16+ (developed on Node 24)
- pnpm 10.x (the repo pins
packageManagerand ships apnpm-lock.yaml)
pnpm install # install dependencies
pnpm run build # compile TypeScript to dist/| Script | What it does |
|---|---|
pnpm run build |
Compile src/ → dist/ with tsc |
pnpm run dev |
Run the CLI from source via ts-node (e.g. pnpm run dev -- pr list -r repo) |
pnpm start |
Run the built CLI (node dist/index.js) |
pnpm run generate:api |
Regenerate the typed API client from the OpenAPI spec |
pnpm run changeset |
Add a changeset describing your changes |
pnpm run version |
Apply pending changesets: bump version + update CHANGELOG.md |
pnpm run release |
Build and publish to npm (changeset publish) |
bitbucket-openapi.json Vendored Bitbucket OpenAPI spec (source of truth)
src/
api/
generated/bitbucket-api.ts Generated client (do not edit by hand)
client.ts Configured Api singleton: auth, pagination, errors
services/ Thin, intention-revealing facades over the client
pullrequests.ts refs.ts branch-restrictions.ts branching-model.ts repositories.ts
commands/ Commander command tree (one folder per top-level command)
pullrequests/ refs/ branches/ repos/ login/ config/ commits/ browse/
utils/ command helpers, formatters, token storage, logger
index.ts Wires the command tree and the preAction hook
The whole thing is built around a generated client, so the type-safe API surface stays in lockstep with Bitbucket's official spec.
- Generated client (
src/api/generated/bitbucket-api.ts) — produced byswagger-typescript-apifrombitbucket-openapi.json. Committed so the project builds without running codegen. - Configured client (
src/api/client.ts) — wraps the generatedApiwith:- Basic auth applied to
instance.defaults.headers.common.Authorization(so it reaches both generated calls and the directinstance.getcalls used to follow pagination links). paramsSerializer: { indexes: null }so repeated query params serialize asstate=OPEN&state=MERGED(what Bitbucket expects), notstate[]=.- A response interceptor that turns axios errors into concise messages (surfacing Bitbucket's
own
error.message). paginate()(followsnextlinks) andunwrap()helpers.
- Basic auth applied to
- Service facades (
src/services/*) — expose clean(api, ref, …)functions and hide the generated methods' awkward, position-sensitive argument order. - Commands (
src/commands/*) — Commander definitions that resolve context, call a service, and render output (human-readable, or--json). Shared helpers live insrc/utils/command.ts.
# 1. Refresh the spec if needed (the published OpenAPI v3 document):
# https://dac-static.atlassian.com/cloud/bitbucket/swagger.v3.json
# save it as bitbucket-openapi.json
# 2. Regenerate:
pnpm run generate:api
pnpm run build
⚠️ A few endpoints have no request-body parameter in the generated client because the spec omits their body schema (e.g.refsBranchesCreate,branchingModelSettingsUpdate). The service layer posts/puts those bodies directly viaapi.instance.post/put— keep that in mind after regenerating.
- Add a function to the relevant
src/services/*facade (or create a new one). - Add a Commander builder under
src/commands/<group>/, usingrunAction,resolveWorkspace,addRepoOptions/addPrOptions, andaddJsonOptionfromsrc/utils/command.ts. - Register it in the group's
index.ts(and register a new group insrc/index.ts).
Releases are managed with Changesets.
# 1. Describe your change (pick patch/minor/major):
pnpm run changeset
# 2. Commit the generated .changeset/*.md file along with your code.
# 3. When ready to release, apply pending changesets (bumps version + writes CHANGELOG.md):
pnpm run version
# 4. Publish (builds first, then publishes with public access):
pnpm run releaseNotes:
- The package is scoped and public (
publishConfig.access: public;.changeset/config.jsonaccess: "public"). CHANGELOG.mdis included in the published tarball (seefilesinpackage.json).- If the npm account has 2FA enabled,
changeset publishcannot prompt for the one-time password. Provide it explicitly:Or use an npm automation token (which bypasses 2FA) for unattended publishes.pnpm run build npm publish --access public --otp=<code>
The published binary is bb (see bin in package.json). To expose it locally during
development, pnpm link --global. To change the command name, edit bin and re-link — see
README.md.