BBC2-14 add bb pr diff#18
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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}/diffreturns a302to/repositories/{ws}/{slug}/diff/{spec}which servestext/plain. The typed openapi-fetch client is JSON-in/JSON-out; rather than fight it, this call uses rawfetch()withAccept: text/plainandredirect: follow. Same precedent aspaginate.ts's raw-fetch cursor follower (noted indocs/bb-notes.md).json: booleanflag 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./diff/{spec}supportscontext,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 toless— scrolling works.delta(if you have it):bun src/index.ts pr diff <id> | delta— renders colorized.bun src/index.ts pr diff <id> --jsonvia global--jsonflag:bun src/index.ts --json pr diff <id>emits{"diff": "..."}.bun src/index.ts pr diffauto-detects.bun test(155 passing, 3 new).bun run lint.Out of scope
delta/ similar for rendering).