feat(bin): add Bitbucket Cloud as a third PR provider - #4
Closed
cloud-practitioner wants to merge 4 commits into
Closed
cloud-practitioner wants to merge 4 commits into
cloud-practitioner wants to merge 4 commits into
Conversation
added 4 commits
September 22, 2026 03:46
Thread bitbucket through the same provider seams github and gitlab already use in bin/fm-pr-lib.sh and bin/fm-pr-merge.sh: URL parsing, the meta/data/registration/poll/snapshot/retirement records, the per-provider record read, and the guarded merge. Bitbucket Cloud is addressed with curl against the REST API v2.0 and no CLI, since it has no gh/glab-style tool, authenticated with a Workspace or Repository Access Token read from FM_BITBUCKET_TOKEN or the calling home's gitignored .env. Green is a policy definition, since Bitbucket Cloud exposes no required-checks flag: every present commit status on the live head must be SUCCESSFUL with none INPROGRESS/FAILED/STOPPED, and at least one status must have reported at all. The merge endpoint has no head-SHA precondition of its own, so the head is re-read and compared immediately before the merge call; the call may return synchronously (200) or asynchronously (202, a pollable task this path does not chase), and either way one live re-read confirms state=MERGED before anything is reported landed, mirroring the GitLab confirm-merged path exactly. bin/fm-pr-poll.sh's Bitbucket branch (curl+jq, same token resolution) is what eventually confirms an unconfirmed landing. Bitbucket Server/Data Center and any CLI or MCP-server binding remain out of scope. Adds docs/bitbucket-backend.md as the design record, extends docs/architecture.md's PR-merge section, and adds tests/fm-pr-bitbucket.test.sh covering URL parsing, a mocked REST record read, and the merge preconditions. (cherry picked from commit 0af199c)
…, not argv (cherry picked from commit 54085cc)
…-file token delivery (cherry picked from commit d967563)
Owner
Author
|
Superseded by the upstream cross-fork PR: kunchenguid#5246 (same attested head 26da6a8). This same-fork PR against the upstream-mirror base was only a by-product of the no-mistakes validation pipeline. |
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.
Intent
Bring the Bitbucket Cloud PR support into the upstream firstmate repository (kunchenguid/firstmate) as a pull request. The change adds Bitbucket Cloud as a third PR provider alongside GitHub and GitLab: URL parsing for Bitbucket PR links, curl+jq reads of the Bitbucket REST v2.0 PR record, poll and merge support, a green-status merge policy, and async 202 confirm-merged handling that mirrors the existing GitLab provider. It also passes the Bitbucket bearer token via a curl config file rather than argv (so it never appears in the process list), and registers a new docs/bitbucket-backend.md describing the config-file token delivery. This same change already merged on the cloud-practitioner/firstmate fork as PR #1 (#1, head commit d967563); it now needs to reach upstream.
What Changed
https://bitbucket.org/<workspace>/<repo>/pull-requests/<n>formatFM_BITBUCKET_TOKENenvironment fallback to.env--squash,--merge,--method, with--rebaseand--allow-redexplicitly refused), head-SHA race-condition detection via pre-merge re-read, and one-shot confirm-merged pollingdocs/bitbucket-backend.mddocumenting identity, authentication, state reading, merge behavior, and task concurrencytests/fm-pr-bitbucket.test.sh); updated security testsRisk Assessment
✅ Low: The change is a well-bounded feature addition that cleanly integrates a third PR provider by following established patterns from GitHub and GitLab, with comprehensive tests, documentation, and security consideration for token handling.
Testing
Validated Bitbucket Cloud PR support through 16 comprehensive unit tests covering URL parsing, token resolution, PR state reading, pre-merge conditions, and merge execution (both synchronous and asynchronous). All tests passed. Verified implementation details: bearer token passed via chmod 600 curl config file (never on argv), green-status merge policy enforced, async 202 responses handled correctly with confirmation re-read, URL validation prevents spoofing, and documentation properly registered and linked.
Evidence: Bitbucket Unit Test Results
Source: Bitbucket Unit Test Results
Evidence: Validation Summary
Source: Validation Summary
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-pr-bitbucket.test.sh - 16 unit tests covering URL parsing, token resolution, PR state reading, pre-merge conditions, and merge executionbash -n bin/fm-pr-lib.sh bin/fm-pr-merge.sh bin/fm-pr-poll.sh bin/fm-pr-check.sh - syntax validationbash -c 'fm_pr_url_parse https://bitbucket.org/my-workspace/my-repo/pull-requests/42' - URL parsing verificationFM_BITBUCKET_TOKEN=ambient-token fm_pr_bitbucket_token /nonexistent - token resolution (ambient env)echo 'FM_BITBUCKET_TOKEN=env-file-token' > /tmp/test-fm-env/.env && fm_pr_bitbucket_token /tmp/test-fm-env - token resolution (.env fallback)fm_pr_url_parse https://bitbucket.org/ws/repo/-/merge_requests/1 - URL validation (reject GitLab paths)grep -n 'chmod 600' bin/fm-pr-lib.sh bin/fm-pr-merge.sh bin/fm-pr-poll.sh - token security (config file chmod 600)grep docs/documentation-audiences.json for bitbucket-backend.md - documentation registrationgrep README.md for bitbucket-backend.md link - README documentation referencegrep docs/architecture.md for bitbucket backend section - architecture documentation update✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.