fix(bitbucket): preserve PR head commits for review guides #18402
main fromrefs/pull/18402/head·merged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHubWhat#
Bitbucket review guides fail before starting the model with “This host did not report the pull request's head commit.”
Preserve source.commit.hash through Bitbucket decoding and provider normalization. The existing PullRequestService then forwards it into PullRequestDetail.headSha.
The decoder accepts absent or null commit metadata and absent or null hashes. The guide's missing-head validation remains unchanged.
Why#
Bitbucket supplies the head commit, but its branch schema and provider mapping discard it. Review guides need that commit to read the exact change.
The user reported this failure in 0.0.46-nightly.20261011.2994. I reproduced the missing SHA in decoder and provider tests against upstream main, 83fbbc18f8718b0254e696f02b8e381386fd6c7b.
Scope and approval#
This qualifies for the small, focused obvious-bug exception in CONTRIBUTING.md. It preserves metadata for an existing capability and changes no product defaults. No prior issue or discussion is required for this exception.
Related: #18124 introduced review guides. This PR adds only the Bitbucket metadata propagation and regression tests. It requires no migration.
How tested#
The three assertions for SHA preservation failed against unchanged main. After the fix, both focused test files pass: 56 tests.
Coverage includes detail and list decoding, getChangeRequest, and absent/null commit and hash metadata.
I ran these commands with Node 24.13.1 and pnpm 11.10.0:
fnm exec --using 24.13.1 pnpm exec vp test run packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.test.ts packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.test.ts
fnm exec --using 24.13.1 pnpm exec vp lint packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.ts packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.ts packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.test.ts packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.test.ts
fnm exec --using 24.13.1 pnpm --filter @t3tools/source-control-bitbucket typecheck
fnm exec --using 24.13.1 pnpm exec vp fmt --check packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.ts packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.ts packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.test.ts packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.test.ts
git diff --check
All commands pass. I ran no repository-wide checks.
I inspected PullRequestReviewGuideService.checkoutHead. It fetches the SHA from the project's primary remote, then falls back to refs/pull/<number>/head.
That fallback names GitHub/Forgejo pull refs. Its Bitbucket compatibility remains unverified if the SHA fetch fails.
Fork-only commits are also a potential checkout limitation: Atlassian's guidance requires access to the source fork.
I did not observe a second checkout failure. This PR leaves the checkout path unchanged and fixes the demonstrated metadata loss.
Live Bitbucket fetching and end-to-end guide generation remain unverified. I did not modify the installed application or live ~/.t3/userdata.
Written by gpt-6.1-sol with high reasoning effort in the Codex harness, through T3 Code.
Fixes #18448
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
7e97fc8Macroscope's review found this PR approvable — This is a narrowly scoped Bitbucket metadata bug fix that restores an existing review-guide path while preserving compatibility when commit metadata is absent. Production changes are limited to decoding and forwarding the existing head SHA, with focused regression coverage and no default or static-analysis changes.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
-
⚙️ Run configuration
-
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ed963163-aeab-41dd-a62d-06d57248dea6
-
📥 Commits
-
-
Reviewing files that changed from the base of the PR and between 1d58b82eadd043f7f7034023d81661affcf94a90 and 6004283a0416d5c54b6cd5023761140d3fdf4125.
-
📒 Files selected for processing (4)
-
-
packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.test.tspackages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.tspackages/source-control-bitbucket/src/server/bitbucketPullRequestJson.test.tspackages/source-control-bitbucket/src/server/bitbucketPullRequestJson.ts
-
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
📝 Walkthrough
-
📝 Walkthrough
-
Walkthrough#
The Bitbucket pull request decoder now reads
headShafrom the source commit hash. It returnsnullwhen the commit hash is missing, null, or blank. The provider includesheadShawhen its value is truthy.Changes#
Bitbucket head commit mapping
Layer / File(s) Summary Decode source commit hash
packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.ts,packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.test.tsThe decoder accepts optional source commit data and sets headShato the trimmed hash ornull. Tests cover detail and page decoding.Expose headShathrough the provider
packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.ts,packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.test.tsThe provider includes headShawhen its value is truthy. Tests check valid and missing source commit values.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
-
Merge Risk: ⚪ Minimal · up to
60042The change is mergeable after normal checks. Live Bitbucket fetching and guide generation remain unverified, but no specific failure is established.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
60042This is a narrow metadata fix using existing repository, checkout, and lifecycle controls. No introduced security finding was established. Commit identity still relies on the configured Bitbucket host, and successful checkout of fork commits was not verified end to end.
Retained concerns No architecture-level concerns identified.
-
Security review details
-
Security Blast Radius
- inferred — The newly enabled operations act through the selected project's Git repository and configured review-guide execution path. The SHA does not select an HTTP credential destination or Git remote. This bounds the observed reachability change but does not establish comprehensive model sandbox isolation.
Trust Boundaries and Controls
- observed — Existing controls restrict credential-bearing API requests and redirects to the configured origin, require the guide's PR repository to match the project, and pass Git commands as structured arguments rather than interpolated shell text. These controls are unchanged by the full PR comparison.
Resilience and Maintainability Implications
- observed — Guide initiation rechecks head identity under a semaphore and joins an existing same-head run. Persistence and completion are ownership-guarded. Scoped finalizers attempt to remove temporary refs and worktrees; ordinary failures become Failed and interruption clears run state. Cleanup errors are logged and ignored, so these mechanisms do not guarantee cleanup after operational failure or abrupt process termination.
Hardening Proposals
- proposed — As defense in depth, validate host-reported commit identifiers before treating them as Git revision arguments and verify the resolved commit matches the reported identifier. This addresses malformed upstream metadata; it is not evidence that an ordinary PR author can inject a revision.
-
Pre-merge checks |
4-
✅ Passed checks (4 passed)
-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly and concisely describes the primary Bitbucket change: preserving pull request head commits for review guides. Description check The description explains the problem, change, scope exception, approval rationale, verification steps, test results, and known limitations. It uses headings different from the template, but it provide…
-
✨ Finishing Touches
-
-
🧪 Generate unit tests (beta)
-
-
- Create a new PR
-
-
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
@Yash-Singh1 can I help and do something more here to unblock pr guides for bitbucket?
Yash-Singh1(GitHub profile, opens in a new tab) approved these changes
Yash-Singh1(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed