Skip to content

Instantly share code, notes, and snippets.

@eins78
Created February 28, 2026 02:25
Show Gist options
  • Select an option

  • Save eins78/930556f8835a96b88b76eebffe2dab1b to your computer and use it in GitHub Desktop.

Select an option

Save eins78/930556f8835a96b88b76eebffe2dab1b to your computer and use it in GitHub Desktop.
bb CLI batch 2 — pr diff/status/activity + source search/commit/diffstat

bb CLI — batch 2 demo

Commands added: pr diff, pr status, pr activity, source search, source commit, source diffstat

bb --help (updated)

$ bb --help
bb — Bitbucket Cloud CLI

Usage: bb <command> [flags]

Setup:
  bb auth login

Auth:
  auth login          Log in with an Atlassian API token
  auth status         Show authenticated user

Pull Requests:
  pr list             List pull requests
  pr view <id>        View a pull request
  pr create           Create a pull request
  pr edit <id>        Edit a pull request (reviewers, title, body)
  pr comment <id>     Comment on a pull request (create, resolve, unresolve)
  pr review <id>      Approve a pull request
  pr merge <id>       Merge a pull request
  pr close <id>       Decline a pull request
  pr tasks <id>       List, resolve, or reopen tasks
  pr diff <id>        Show PR diff (or --stat for summary)
  pr status           Show PRs you authored or are reviewing
  pr activity <id>    Show PR activity timeline

Source:
  source ls [path]    List files and directories
  source cat <path>   Print file contents
  source branch       List branches
  source tag          List tags
  source search <q>   Search code in the repository
  source commit [ref] Show commit details
  source diffstat <s> Compare two refs (e.g., main..feature)

Global flags:
  -R workspace/repo   Specify repository (default: auto-detect from git remote)
  --json              Output raw JSON

Environment:
  BB_TOKEN            API token (overrides keychain)
  BB_EMAIL            Account email (overrides keychain)

Examples:
  bb pr list
  bb pr list --state merged --json
  bb pr view 42 --comments
  bb pr create --title "Add feature" --body "Details..." --reviewer alice
  bb pr edit 42 --add-reviewer bob --remove-reviewer alice
  bb pr comment 42 --body "Looks good!"
  bb pr comment 42 --resolve 12345
  bb pr tasks 42
  bb pr tasks 42 --resolve 12345
  bb pr merge 42 --squash --delete-branch
  bb source ls
  bb source ls src/ --ref develop
  bb source cat README.md
  bb source cat package.json --ref v1.0.0
  bb source branch
  bb source tag --json
  bb pr diff 42
  bb pr diff 42 --stat
  bb pr status
  bb pr activity 42
  bb source search "TODO"
  bb source search "className" --all
  bb source commit
  bb source diffstat main..feature/x

pr diff

$ bb pr diff 70 | head -30
diff --git a/claude-code/README.md b/claude-code/README.md
index d779963..12b1c19 100644
--- a/claude-code/README.md
+++ b/claude-code/README.md
@@ -31,7 +31,7 @@ Reusable skills in `skills/`.
 | `implementing-bdd-scenarios` | Step definitions, Page Objects, async handling, selectors, waiting strategies |
 | `jest-testing-conventions` | Jest unit testing: jest.fn/spyOn/mock, clear/reset/restore, AAA pattern, fake timers |
 | `handling-pull-requests` | PR workflow guidance: creating PRs, addressing review feedback, reply conventions |
-| `working-with-bitbucket-api` | Bitbucket Cloud API via `bb` CLI — PR operations (list, view, create, comment, approve, merge). Requires `install-dependencies.sh` |
+| `working-with-bitbucket-api` | Bitbucket Cloud API via `bb` CLI — PR operations (list, view, create, comment, approve, merge) and source browsing (ls, cat, branch, tag). Requires `install-dependencies.sh` |
 | `working-with-bitbucket-web` | Bitbucket web UI navigation (elements, rich text editor, comment threads) |
 | `working-with-jira-web` | JIRA web UI navigation (create issues, fill forms, link tickets, wiki markup) |
 | `writing-clearly-and-concisely` | Strunk's *Elements of Style* (1918) for clear prose—docs, commits, error messages, UI text. [Source](https://github.com/obra/the-elements-of-style) |
@@ -61,7 +61,7 @@ Reusable skills in `skills/`.
 - `show-your-work`: `"show your work"` — creates executable demo docs with screenshots and command output
 - `story-tracking`: `"continue on FOOBAR-1234"` or `"create a story for the WCAG audit"`
 - `story-tracking` + `markdown`: Complementary — `story-tracking` covers structure, `markdown` covers syntax
-- `working-with-bitbucket-api` + `working-with-bitbucket-web`: Complementary — API skill handles PR operations via `bb` CLI, web skill handles rich text and images. Run `install-dependencies.sh` to set up `bb`
+- `working-with-bitbucket-api` + `working-with-bitbucket-web`: Complementary — API skill handles PR operations and source browsing via `bb` CLI, web skill handles rich text and images. Run `install-dependencies.sh` to set up `bb`

pr diff --stat

$ bb pr diff 70 --stat
STATUS   ADDED   REMOVED   PATH
modified  +2    -2  claude-code/README.md
modified  +270  -0  claude-code/skills/working-with-bitbucket-api/bin/bb

pr status

$ bb pr status
Authored (2):
ID   STATE   AUTHOR   BRANCH   TITLE
70  OPEN  Qubert  feature/bb-source-commands  Add source command group to bb CLI
69  OPEN  Qubert  feature/bb-cli              Add working-with-bitbucket-api skill with bb CLI

Reviewing (0):
  (none)

pr activity

$ bb pr activity 70
DATE   TYPE   AUTHOR   SUMMARY
2026-02-27  update  Qubert  OPEN
2026-02-27  update  Qubert  OPEN

source search

$ bb source search "import" --all | head -20
FILE   MATCHES   LINES
basel-stadt-html-prototype-mobile/webapp/vendor/bundle/ruby/1.8/gems/sass-3.3.2/lib/sass/tree/import_node.rb     12  2,3,4,...
extensions/src/main/java/ch/stzh/cq/extensions/importservice/impl/sar/ImportFileSelector.java                    84  2,3,4,...
importer/importer-bundle/src/test/java/ch/stzh/cq/importer/importservice/api/ImportResultTest.java               51  2,3,4,...
extensions/src/main/java/ch/stzh/cq/extensions/importservice/impl/ImportServiceImpl.java                         49  2,3,4,...
packages/eslint-plugin-elements/src/utils/import-analyzer.ts                                                     60  1,2,3,...
...

source commit

$ bb source commit
Commit:   6d3b5dc1fb78
Author:   Qubert <qubert@quatico.com>
Date:     2026-02-27T23:41:04+00:00
Parents:  1b53b13bfcbe

F Add source command group to bb CLI (ls, cat, branch, tag)

New `bb source` subcommands for browsing repository contents via
Bitbucket REST API v2 — file listing, content viewing, branch and
tag enumeration. Includes bb_api_raw helper for raw content fetch,
bb_current_ref for detecting current branch as default --ref.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

source commit (branch with slashes)

$ bb source commit feature/bb-source-commands
Commit:   6d3b5dc1fb78
Author:   Qubert <qubert@quatico.com>
Date:     2026-02-27T23:41:04+00:00
Parents:  1b53b13bfcbe

F Add source command group to bb CLI (ls, cat, branch, tag)
...

Branch names with / are resolved to SHAs via /refs/branches/{name} before calling the commit endpoint.

source diffstat

$ bb source diffstat master..feature/bb-source-commands
STATUS   ADDED   REMOVED   PATH
modified  +3     -1   claude-code/README.md
modified  +17    -11  claude-code/skills/handling-pull-requests/SKILL.md
added     +30    -0   claude-code/skills/working-with-bitbucket-api/README.md
added     +100   -0   claude-code/skills/working-with-bitbucket-api/SKILL.md
added     +1474  -0   claude-code/skills/working-with-bitbucket-api/bin/bb
added     +33    -0   claude-code/skills/working-with-bitbucket-api/install-dependencies.sh
modified  +11    -11  claude-code/skills/working-with-bitbucket-web/SKILL.md
modified  +3     -1   package.json

Note: Bitbucket's diffstat spec is reversed from git ({new}..{old}). The CLI accepts git-style base..head and swaps internally.

error handling

$ bb source commit nonexistent
error: HTTP 404 — Commit not found
Exit: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment