Skip to content

feat(bitbucket): add guarded cloud PR comment create - #1142

Merged
potiuk merged 1 commit into
apache:mainfrom
KatalKavya96:feat-bitbucket-cloud-pr-comment-create
Sep 7, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
KatalKavya96:feat-bitbucket-cloud-pr-comment-create

Conversation

@KatalKavya96

Copy link
Copy Markdown
Member

Summary

  • Adds magpie-bitbucket pr comment <id> --body-file <path> for creating a top-level Bitbucket Cloud pull-request comment.
  • Reuses the existing guarded write path: HTTPS-only JSON POSTs, redirect rejection, quoted path segments, body-file input, and caller-side explicit confirmation.
  • Keeps Bitbucket Data Center PR comment writes explicitly unsupported for this PR so the mutation surface stays narrow.

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

  • For Python packages touched: full Bitbucket pytest suite passes

  • ruff check src tests passes

  • ruff format --check src tests passes

  • mypy src tests passes

  • git diff --check passes

  • Focused PR-comment tests cover:

    • Cloud POST URL and JSON body
    • Data Center unsupported behaviour
    • created-comment normalization
    • CLI success
    • empty body rejection before write
    • missing body-file rejection before write
  • prek run --all-files passes

  • For Groovy bridges touched: command-line invocation tested end-to-end

  • For skill changes: eval suite passes for the affected skill

  • For skill behaviour changes: a new or updated eval fixture is included

RFC-AI-0004 compliance

  • HITL — the bridge executes an already-confirmed mutation; explicit confirmation remains the responsibility of the calling skill.
  • Sandbox — no new unrestricted host access; the existing Bitbucket network boundary is reused.
  • Vendor neutrality — extends the existing partial Bitbucket change-request adapter without claiming complete backend parity.
  • Conversational + correctable — the caller remains responsible for presenting and confirming the proposed comment before invoking the write.
  • Write-access discipline — only one explicitly requested top-level PR comment is created; no autonomous review, approval, decline, merge, or task mutation is added.
  • Privacy LLM — pull-request comment content remains external repository data and follows the existing privacy / approved-LLM handling rules.

Linked issues

Refs #606
Follow-up to #1078

Notes for reviewers

This is the next narrowly scoped Bitbucket write after Cloud issue-comment creation.

The new command is:

magpie-bitbucket pr comment <id> --body-file <path>

Implementation details:

  • Bitbucket Cloud only
  • sends JSON to the existing pull-request comments endpoint
  • reads the comment body only from --body-file
  • rejects missing or whitespace-only body files before any outbound mutation
  • reuses post_json(), including HTTPS enforcement and redirect rejection
  • quotes the pull-request ID as a path segment
  • normalises the created comment through the existing Cloud pull-request comment normalizer
  • keeps Bitbucket Data Center PR comment writes explicitly unsupported

Out of scope for this PR: inline comments, comment edits/deletion, PR task mutation, review submission, approve/unapprove, decline, merge, PR creation/editing, issue mutation, or build mutation.

@KatalKavya96

Copy link
Copy Markdown
Member Author

Hi @potiuk, this continues the guarded Bitbucket write rollout after #1078.

This adds one narrow mutation: top-level Bitbucket Cloud PR comment creation via pr comment <id> --body-file <path>.

It deliberately reuses the existing write-path protections from issue-comment creation: caller-side confirmation, body-file-only input, HTTPS enforcement, redirect rejection, and quoted path segments. Data Center PR comment writes remain explicitly unsupported in this PR.

Tests cover the POST request/body, normalization, CLI success, Data Center rejection, and missing/empty body failures before any write occurs.

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the one PR in my current batch that adds an outbound write, so I weighted the review toward the gate rather than the plumbing. The gate holds up.

What I verified beyond CI:

  • _read_body_file raises before _dispatch ever reaches backend.create_pull_request_comment, and both guard tests assert assert_not_called() on the network function. The empty-body case uses " " rather than an empty string, so whitespace-only bodies are covered too — that is the right level of paranoia for a write path.
  • Data Center fails closed, raising rather than no-op'ing or falling through to a Cloud URL.
  • quote_path is applied to workspace, repo slug, and the caller-supplied pull-request id.
  • 136 tests pass at this head; ruff check, ruff format --check and mypy are all clean.
  • created_pull_request_comment mirrors the existing created_issue_comment precedent exactly — same ok semantics, same raw passthrough, same backend naming. Matching the established shape is the right call for a bridge.
  • The capability-table row is honest about scope ("Partial write, Cloud only"), and the follow-up list correctly drops PR comment creation now that it exists.

HITL discipline is preserved: the bridge executes an already-confirmed action and the README puts the confirmation caller-side, consistent with the existing issue comment command.

One minor inline note about a comment block that ended up documenting the wrong function. I am resolving it so it does not block the merge.

Separately, and explicitly not something for you to fix here: docs/vendor-neutrality.md still describes this bridge as partial-read-only in two places. That was already inaccurate before this PR, since Cloud issue-comment writes pre-date it. Pre-existing drift that deserves its own pass.


🤖 This review was drafted by an AI-assisted tool and may contain mistakes. It has been reviewed and confirmed by an Apache Magpie maintainer before submission. See CONTRIBUTING.md for what this project considers a maintainer review.

@potiuk
potiuk merged commit 9c1fdd4 into apache:main Sep 7, 2026
9 checks passed
@potiuk potiuk added contract:change-request Tool capability: proposed-change review + merge gate (PR / MR / Gerrit change) contract:tracker Tool capability: issue / board / label backend labels Sep 25, 2026
@potiuk potiuk added family:docs Docs, MISSION.md, READMEs family:tools tools/* labels Nov 1, 2026
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 family:docs Docs, MISSION.md, READMEs family:tools tools/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants