feat: numeric-id positional heuristic for PR commands (bb pr 42 from inside a checkout)#40
Conversation
bb pr 42 from inside a checkout now treats 42 as the PR id and auto-detects the repo from git context, instead of treating 42 as a repo slug and erroring with 'Usage: bb pr-view [repo] <pr-id>'. Mirrors the state-recognition heuristic v1.2.0 added for cmd_pr_list (bb prs MERGED). Same gotcha class, same fix shape. New helper _resolve_pr_args centralizes the heuristic: if $1 is purely digits, treat it as the id (auto-detect repo); otherwise the existing positional form ([repo] <id>) is preserved. Sets caller-scope repo / pr_id / pr_args_consumed so callers with trailing args (cmd_pr_merge strategy at slot 3-or-2, cmd_pr_comment_add body at slot 3-or-2) 'shift $pr_args_consumed' to reach extras uniformly. Applied to all 8 PR-id commands: cmd_pr_view, cmd_pr_diff, cmd_pr_comments, cmd_pr_approve, cmd_pr_unapprove, cmd_pr_merge, cmd_pr_decline, cmd_pr_comment_add. Edge case: a repo literally named with pure digits (slug '42') would be shadowed. Acceptable since Bitbucket slugs are lowercase-hyphenated by convention; the explicit 'workspace/42 <id>' form remains an escape hatch (the heuristic only triggers on the bare-digits form). End-to-end verification against daniel-pittman/bb-cli-test PR#2: bb pr 2 -> shows PR with auto-detected repo bb pr-diff 2 -> shows diff bb pr-merge 2 -> merges (also exercises v1.4.3's POST fix) bb pr <ws>/<repo> 2 -> old form still works bb pr -> usage error still fires, message updated MCP side unaffected: Python tools take named args (pr_id=42), not positionals, so this gotcha can't fire there. 565 pytest tests pass.
|
Claude finished @daniel-pittman's task in 4m 20s —— View job Code Review —
|
…med' Reviewer caught a real regression my happy-path smoke missed: `bb pr-merge myrepo` (a single non-numeric arg, repo without id) hits `shift 2` against $# == 1, which returns non-zero, which under 'set -euo pipefail' aborts the script BEFORE the friendly Usage: message can fire. User sees a silent exit 1 where they previously got a clear usage hint. Fix: move the empty-pr_id check above the shift in both functions that shift. Once pr_id is verified non-empty, the consumed args are guaranteed present so the shift is safe. cmd_pr_merge — single check before shift. cmd_pr_comment_add — split into two checks (pr_id before shift, body after) because body lives in the post-shift slot. Factored the Usage message into a local _usage_pr_comment helper so both checks emit the same text. Also: extended both Usage messages to surface the new short form (`bb pr-merge <id> [strategy] from inside a checkout` etc.) so the heuristic is discoverable from the error path too. Smoke-verified the 4 regression cases (bb pr-merge myrepo, bb pr-comment myrepo, bb pr-comment myrepo 42, bb pr-merge): all now print the Usage message with exit=1. Happy path (bb pr 1 in a checkout) unchanged.
Semgrep (OSS): no findingsClean scan. Posted before the Claude review. |
CI Tests✅ Tests passed: the pytest suite across Python 3.10/3.11/3.12 (and bash syntax checks) is green on Posted before the Claude review so the test outcome is folded into the review. |
|
Claude finished @daniel-pittman's task in 1m 44s —— View job Code Review —
|
Review Gate✅ Gate: PASS — Review reported no HIGH/CRITICAL findings. Observe-only until |
What this fixes
From inside a Bitbucket git checkout,
bb pr 42(orbb pr-merge 42,bb pr-diff 42, etc.) used to treat42as the repo slug, error withUsage: bb pr-view [repo] <pr-id>, and the user had to type the redundantbb pr workspace/repo 42even when sitting in that exact checkout. The natural one-arg invocation now Just Works.Approach
Same gotcha class as the v1.2.0 state-recognition heuristic for
bb prs OPEN. Same fix shape.New helper
_resolve_pr_argscentralizes the heuristic: if$1is purely digits, treat it as the id (auto-detect repo from git); otherwise the existing positional form ([repo] <id>) is preserved unchanged. Sets caller-scoperepo/pr_id/pr_args_consumedso callers with trailing args (cmd_pr_mergestrategy,cmd_pr_comment_addbody)shift $pr_args_consumedto reach extras uniformly.Applied to all 8 PR-id commands:
cmd_pr_view,cmd_pr_diff,cmd_pr_commentscmd_pr_approve,cmd_pr_unapprove,cmd_pr_declinecmd_pr_merge(usesshift $pr_args_consumedfor the strategy slot)cmd_pr_comment_add(usesshift $pr_args_consumedfor the body slot)The MCP / Python side is unaffected because its tools take named kwargs (
pr_show(pr_id=42, repo="")), not positionals, so this gotcha can't fire there.Edge case (accepted)
A repo literally named with pure digits (slug
42) would be shadowed by the heuristic. Acceptable: Bitbucket slugs by convention are lowercase-hyphenated, pure-digit slugs are vanishingly rare, and the explicitworkspace/42 <id>form is the escape hatch (the heuristic only triggers on the bare-digits form).End-to-end verification (against
daniel-pittman/bb-cli-testPR #2)Tests
Docs
cmd_helpNOTES section gets a one-paragraph callout describing the heuristic so it's discoverable frombb help.cmd_pr_viewusage error mentions the new short form.Release
Bundle with the v1.4.3 patch already on develop (PR #39 / commit
138c236— thebb pr-mergePOST fix). v1.4.3 carries both fixes.