Skip to content

BBC2-14 add bb pr diff#18

Merged
b2l merged 1 commit into
mainfrom
b2lpowa/bbc2-14-view-the-diff-of-a-pull-request
Apr 15, 2026
Merged

BBC2-14 add bb pr diff#18
b2l merged 1 commit into
mainfrom
b2lpowa/bbc2-14-view-the-diff-of-a-pull-request

Conversation

@b2l
Copy link
Copy Markdown
Owner

@b2l b2l commented Apr 15, 2026

Summary

New bb pr diff [<id>] command. Defaults to the PR for the current branch. JSON mode wraps as {"diff": "..."}.

Implementation notes

  • GET /pullrequests/{id}/diff returns a 302 to /repositories/{ws}/{slug}/diff/{spec} which serves text/plain. The typed openapi-fetch client is JSON-in/JSON-out; rather than fight it, this call uses raw fetch() with Accept: text/plain and redirect: follow. Same precedent as paginate.ts's raw-fetch cursor follower (noted in docs/bb-notes.md).
  • Renderer interface gets a json: boolean flag so commands whose natural output is a raw blob (like a diff) can branch cleanly between "write bytes verbatim" and "emit JSON object." Tiny addition, used exactly once here.
  • No query-param flags in v1 (per ticket). /diff/{spec} supports context, path, ignore_whitespace, binary, renames — easy to add later if someone asks.

Test plan

  • bun src/index.ts pr diff <id> on a real PR prints the unified diff. Pipe to less — scrolling works.
  • Pipe to delta (if you have it): bun src/index.ts pr diff <id> | delta — renders colorized.
  • bun src/index.ts pr diff <id> --json via global --json flag: bun src/index.ts --json pr diff <id> emits {"diff": "..."}.
  • No-id form: from a branch with an open PR, bun src/index.ts pr diff auto-detects.
  • On a non-existent PR: clean error, exit 1 (not a stack trace).
  • Tests: bun test (155 passing, 3 new).
  • Lint: bun run lint.

Out of scope

  • Filtering by path / context / whitespace flags.
  • Structured hunks in JSON mode (users pipe to delta / similar for rendering).
  • Color on TTY — we pass bytes verbatim; coloring is the user's pipeline.

Prints the unified diff of a PR to stdout. Defaults to the open PR
for the current branch when no id is given. JSON mode wraps as
{"diff": "..."}.

GET /pullrequests/{id}/diff is a 302 redirect to
/repositories/{ws}/{slug}/diff/{spec} which serves text/plain, so
we bypass the typed openapi-fetch client and hit fetch() directly
with Accept: text/plain and redirect: follow.

To let the command branch between 'write bytes verbatim' and 'emit
{"diff": ...}', the Renderer interface gains a `json: boolean`
flag. Cheap addition; removes the awkwardness of abusing
renderer.detail() for raw text output.
@b2l b2l merged commit ce0457a into main Apr 15, 2026
1 check passed
@b2l b2l deleted the b2lpowa/bbc2-14-view-the-diff-of-a-pull-request branch April 15, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant