Skip to content

feat(bitbucket): add guarded cloud PR merge - #1471

Open
KatalKavya96 wants to merge 3 commits into
apache:mainfrom
KatalKavya96:feat-bitbucket-cloud-pr-merge
Open

KatalKavya96 wants to merge 3 commits into
apache:mainfrom
KatalKavya96:feat-bitbucket-cloud-pr-merge

Conversation

@KatalKavya96

Copy link
Copy Markdown
Contributor

Summary

  • Adds guarded Bitbucket Cloud pull-request merge support via magpie-bitbucket pr merge <id> --strategy {merge,squash,rebase}.
  • Maps the Cloud merge path onto the change-request land(id, strategy) -> landed_ref contract shape, including extraction of the resulting merge commit when available.
  • Keeps Bitbucket Data Center merge writes explicitly fail-closed and preserves queued/submitted merge state instead of reporting an incomplete merge as already landed.

Type of change

  • Skill change (.claude/skills/<name>/) — eval fixtures updated below
  • Tool / bridge contract (tools/<system>/*.md)
  • Python package (tools/*/ with pyproject.toml)
  • Groovy reference impl
  • Cross-cutting (RFC, AGENTS.md, sandbox, privacy-LLM)
  • Documentation (docs/, README.md, CONTRIBUTING.md)
  • Project template (projects/_template/)
  • CI / dev loop (prek, workflows, validators)
  • Other:

Test plan

  • prek run --all-files passes
  • For Python packages touched: uv run pytest / ruff check / mypy passes
  • For Groovy bridges touched: command-line invocation tested end-to-end
  • For skill changes: eval suite passes for the affected skill
    (PYTHONPATH=tools/skill-evals/src python3 -m skill_evals.runner tools/skill-evals/evals/<skill>/)
  • For skill behaviour changes: a new or updated eval fixture is included in this PR
    (a regression test for the bug fixed / the behaviour added — see CONTRIBUTING.md)
  • Other:
    • focused merge tests cover strategy payload, completed merge normalization, queued merge normalization, landed_ref, Data Center fail-closed behavior, and CLI dispatch
    • full Bitbucket test suite passes
    • git diff --check passes
    • workspace pytest passes with a short macOS temp path to avoid the unrelated AF_UNIX pathname-length limitation

RFC-AI-0004 compliance

  • HITL — the merge mutation remains gated on explicit caller-side user confirmation
  • Sandbox — no new unrestricted host access; the implementation reuses the existing guarded HTTPS write path
  • Vendor neutrality — the Bitbucket-specific command is mapped onto the generic change-request land contract rather than introducing a new framework-level vendor

@KatalKavya96

Copy link
Copy Markdown
Contributor Author

Hi @potiuk — next narrow #606 follow-up after #1194.

This adds guarded Bitbucket Cloud pr merge <id> --strategy {merge,squash,rebase}, maps it onto the change-request land(id, strategy) -> landed_ref contract shape, preserves queued merge state, and keeps Data Center merge writes fail-closed.

Focused/full Bitbucket tests, Ruff, mypy, repository hooks, and workspace pytest are green.

Would appreciate your review when you get a chance.

@github-actions github-actions Bot added contract:tracker Tool capability: issue / board / label backend contract:change-request Tool capability: proposed-change review + merge gate (PR / MR / Gerrit change) labels Sep 29, 2026

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @KatalKavya96!

The overall structure and Data Center fail-closed handling look solid. However, there are two discrepancies between the documented contract shape and the implementation:

  1. Missing --strategy in CLI & Payload:

    • README.md and the PR summary document pr merge <id> --strategy {merge,squash,rebase}, but --strategy is missing from _build_parser() in cli.py.
    • cloud.merge_pull_request() currently hardcodes payload={"type": "pullrequest"} without accepting or mapping the strategy parameter to Bitbucket's API values (merge_commit, squash, fast_forward).
  2. Missing landed_ref normalization:

    • The documentation mentions returning the merge commit as landed_ref when available, but in normalize.py (merged_pull_request), landed_ref is not extracted from result_data.get("merge_commit", {}).get("hash").

Could you add --strategy to cli.py / cloud.py and extract landed_ref in normalize.py along with matching tests?

@KatalKavya96

KatalKavya96 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @Kaap10

I updated the PR to:

  • add required --strategy {merge,squash,rebase} CLI handling

  • map those values to Bitbucket Cloud merge strategies

  • pass the selected strategy through the merge request

  • extract merge_commit.hash as landed_ref

  • preserve queued merges without reporting a landed ref prematurely

  • add matching strategy, normalization, CLI, and Data Center fail-closed tests

Thanks for catching the contract/implementation mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contract:change-request Tool capability: proposed-change review + merge gate (PR / MR / Gerrit change) contract:tracker Tool capability: issue / board / label backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants