Skip to content

feat(bitbucket): connect Bitbucket from Settings and create pull requests - #5832

Merged
nwparker merged 12 commits into
mainfrom
nwparker/bitbucket-disc
Aug 11, 2026
Merged

nwparker merged 12 commits into
mainfrom
nwparker/bitbucket-disc

Conversation

@nwparker

@nwparker nwparker commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Connect Bitbucket from Settings — no env vars, no restart

Bitbucket Cloud is the only review provider Orca can't connect to from inside the app. GitHub and GitLab delegate auth to the gh / glab CLIs, which own keychain storage and OAuth. Bitbucket has no comparable first-party CLI, so today the only way to authenticate is to set ORCA_BITBUCKET_* environment variables and restart — which is what discussion #5364 ran into.

This adds an in-app credential flow that mirrors what Linear and Jira already do: type the token into Orca, it's verified before saving, encrypted with Electron safeStorage, and the connection renders from plaintext metadata so opening Settings never triggers a keychain prompt.

Environment variables still win, so existing headless / SSH / CI setups are untouched.

While testing this with a real Bitbucket user, it turned out credentials were only half the problem — Orca could never create a Bitbucket pull request at all, however it was authenticated. That's fixed here too; see Creating pull requests below.

Visual proof

Captured against this branch in a dev build (Settings → Integrations).

Before — env-var instructions only, no way to connect from the app:

before

After — a Connect button:

after

The dialog, in both auth modes:

Email + API token (default) Access token
basic token

Verify-before-save — a junk token hitting the real Bitbucket API. Rejected inline, dialog stays open, and ~/.orca/bitbucket-credential.* is not created:

rejected

Env precedence — same build relaunched with ORCA_BITBUCKET_ACCESS_TOKEN set. The card switches to env-managed messaging and drops the Connect/Disconnect affordances entirely. ("Auth failed" because the demo token is deliberately fake — env credentials are checked live, unlike stored ones.)

env managed

What you get

Settings → Integrations → Bitbucket now has Connect / Edit credentials / Disconnect:

  • Two auth modes — Email + Atlassian API token (HTTP Basic, the recommended path, default) or an access token (Bearer). Optional API base URL override.
  • Verified before saved — the dialog calls Bitbucket /user with what you typed; a dead token is rejected inline and nothing is written to disk.
  • No relaunch — connect/disconnect resets the preflight cache, so the card and worktree PR data pick up the new credential immediately.
  • Env-managed connections show "Configured via environment variables" and deliberately hide Disconnect — Orca can't unset your environment.

Creating pull requests

bitbucketForgeProvider had supportsReviewCreation: false and no createReview, so Create reported "This repository provider does not support creating a pull request from Orca" on every Bitbucket repo — the complaint that started this thread. Adds createBitbucketPullRequest against POST /repositories/{workspace}/{repo}/pullrequests, resolving auth through the same env-first / stored-credential path as lookups.

Four follow-on bugs surfaced during real-account testing:

  • A merged PR blocked the branch's next one. The branch lookup queries every PR state and returns the most recently updated, so a merged PR came back as the branch's current review and eligibility refused to create. Bitbucket only discarded such a match on the default branch ([Bug]: Wrong PR diffs displayed when checking out the default branch #9171); GitHub already drops any merged PR it matched by branch alone. Bitbucket now does the same.
  • A second capability list. supportsReviewCreation on the forge provider is not what the blocker reads — src/shared/hosted-review-creation-providers.ts is, and it never listed bitbucket. Both lists now agree, with a test asserting they stay in sync.
  • Created PRs were never linked. The two updateWorktreeMeta call sites had a per-provider if chain with no bitbucket branch, so a created PR succeeded and then wasn't linked to the worktree. Now an exhaustive resolveCreatedHostedReviewLink switch, so a new provider fails to compile rather than silently going unlinked.
  • Linked PRs resolve by number first. Bitbucket's branch index is eventually consistent, so a freshly created PR could be missing from it; a stale linked number falls back to the index instead of swallowing the lookup.

No draft pull requests. Bitbucket Cloud's API has no such concept, so the composer hides the Draft toggle for Bitbucket and forces the flag off at submit rather than quietly publishing a live PR.

Bitbucket also fell through to GitHub's review copy, so some strings read "GitHub" on a Bitbucket repo.

How it's stored

Path Contents Encrypted
~/.orca/bitbucket-credential.enc { accessToken, apiToken } Yes — safeStorage, 0600 plaintext fallback when no OS keyring
~/.orca/bitbucket-credential.json { version, authMode, email, baseUrl, account, updatedAt } No (non-secret)

Both files are written 0600. The secret is never logged and never crosses IPC back to the renderer — bitbucket:status returns only non-secret fields.

The no-keychain-prompt guarantee

This is the part worth reviewing closely. Three layers, mirroring Linear:

  1. Plaintext metadata holds the account/email/baseUrl, so the card renders "Connected as X" with zero decryption.
  2. Lazy decrypt — loadStoredBitbucketSecret({ force }) returns the in-memory cache if warm; without force it returns null without touching disk. Only a real API call forces a decrypt, once, then caches.
  3. Preflight cache already memoizes source-control status per session.

getBitbucketAuthStatus() refines this: if the secret happens to be warm in memory from an earlier PR fetch, it does revalidate against /user (free — no decrypt), so a revoked token surfaces on the next "Re-check". If the cache is cold it trusts the metadata rather than prompting.

status-no-decrypt.test.ts simulates a cold session and asserts safeStorage.decryptString is never called by either status path, and exactly once when a PR is actually fetched.

Auth resolution

PR fetch / status ──▶ env vars have auth?
                        │yes → use env (never decrypts)
                        │no  → stored credential present?
                                 │yes → decrypt lazily (cached), or trust metadata for status
                                 │no  → not configured

Every Bitbucket API path already funnels through src/main/bitbucket/client.ts, so wiring the fallback there covers PR fetching, build statuses, and hosted-review creation in one place.

Files

File What
bitbucket-auth-config.ts (new) Env reading, hasAuth, authHeaders, shared config type — extracted from client.ts
user-request.ts (new) fetchBitbucketUser() — shared by status checks and connect-time verification
credential-store.ts (new) Encrypted secret + plaintext metadata, lazy decrypt, in-memory caches
credential-connection.ts (new) connectBitbucket (verify → save), disconnectBitbucket, getBitbucketConnectionStatus
client.ts Resolves auth env-first / stored-fallback; status never decrypts
src/main/ipc/bitbucket.ts (new) bitbucket:connect / :disconnect / :status, resets preflight cache
src/shared/bitbucket-credentials.ts (new) Wire types shared by main, preload, and renderer
integration-credential-file.ts Added shared writeEncryptedCredential() (Linear/Jira duplicated this)
bitbucket-credentials-dialog.tsx (new) Connect/edit dialog
bitbucket-integration-card.tsx (new) Card extracted from token-source-control-integration-cards.tsx (max-lines)

Testing

Automated:

  • credential-store.test.ts — persist/read-back, 0600 perms, the lazy-decrypt invariant, malformed-JSON field narrowing, and that a failed delete surfaces instead of silently leaving files on disk.
  • credential-connection.test.ts — verify-before-save, reject on 401 without persisting, reject incomplete Basic creds with no network call, Basic header shape, env precedence, disconnect.
  • status-no-decrypt.test.ts — cold-session no-decrypt invariant, decrypt-exactly-once on a real fetch, revalidation when the cache is warm.
  • client.test.ts unchanged and passing — the env path keeps its exact return shape.
npx vitest run src/main/bitbucket/ src/main/ipc/register-core-handlers.test.ts src/preload/
pnpm run typecheck
pnpm run lint

Verified against a real Bitbucket Cloud account by @devatnull, who doesn't have my problem of not owning one. They ran the flow end to end across five adhoc builds and confirmed: connect works, PR creation succeeds, the new PR appears immediately, and it stays linked after it's closed or merged. Four of the bugs above came out of that testing, and they contributed the fixes for two of them in #13795 (merged into this branch).

Still unverified: the keyring-unavailable fallback, and any non-macOS platform.

Deliberately out of scope

  • Bitbucket Server / Data Center — repo detection still hardcodes the bitbucket.org host in repository-ref.ts. The store already carries a custom baseUrl, so this is mostly relaxing that host check.
  • OAuth sign-in — would be the nicest end state; drops in via saveBitbucketCredential with authMode: 'token'.
  • Remote-runtime connect — credentials are local-machine only, so on a remote runtime the dialog explains to use ORCA_BITBUCKET_* on the remote instead. Needs a bitbucket.* RPC to lift.
  • Azure DevOps / Gitea in-app entry — same pattern templates cleanly; writeEncryptedCredential and the IntegrationCredentialService union are already shared.

Credits

@devatnull did the real-account testing this needed and contributed #13795. The linking bug in particular was mine and their fix is better than what I'd have written.

Rollback

Self-contained and additive. Reverting removes the feature with no migration; older builds simply ignore ~/.orca/bitbucket-credential.* and the env-var path is unchanged.

Made with Orca 🐋

@ghost

ghost commented Jun 19, 2026 •

Copy link
Copy Markdown

@nwparker

Copy link
Copy Markdown
Contributor Author

No keychain prompt when opening Settings

Confirmed + regression-tested that opening the Settings page never decrypts the stored secret (which would trigger the OS "unlock keychain" prompt):

  • The card's two status paths — getBitbucketAuthStatus (preflight) and getBitbucketConnectionStatus (the bitbucket:status IPC the card calls on mount) — read plaintext metadata only (hasStoredBitbucketCredential + getStoredBitbucketMetadata). No safeStorage.decryptString.
  • The secret is decrypted only by resolveRequestAuth during an actual PR/build-status fetch, lazily and cached after the first decrypt — so at most one decrypt per session, and not on Settings open or on "Re-check".
  • New test src/main/bitbucket/status-no-decrypt.test.ts simulates a cold session (secret on disk, memory cache empty) and asserts decryptString is never called by the status reads.

Tradeoff (intentional): a stored connection isn't live-revalidated on each Settings open — the card trusts the account resolved at connect time. That's the price of not prompting; a revoked token surfaces when a PR fetch fails rather than on the card. Flag if you'd prefer the opposite.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds end-to-end Bitbucket credential integration. The change defines shared authentication contracts, environment-based authentication, encrypted credential storage, user verification, and connection status handling. It refactors Bitbucket API requests to resolve environment or stored credentials. It adds IPC and preload APIs, pull-request creation, provider wiring, settings components, search metadata, tests, and English localization. It also prevents draft review creation for Bitbucket.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main changes: in-app Bitbucket connection from Settings and pull-request creation support.
Description check ✅ Passed The description clearly covers the change, visuals, testing, security-related storage, platform limitations, and follow-up scope, though it omits some template headings.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
src/renderer/src/components/settings/bitbucket-credentials-dialog.tsx (1)

265-265: ⚡ Quick win

Replace arbitrary text-[11px] with a style token class.

Line 265 introduces an ad-hoc font size in renderer UI. Use a documented typography token/class from the style system instead.

As per coding guidelines, “Never invent new color values, font sizes, or shadow tiers when a documented one in STYLEGUIDE.md already covers the role.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ef54c8d6-8f5d-43d8-b2ce-7313b316bd72

📥 Commits

Reviewing files that changed from the base of the PR and between ef45305 and a769ab7.

📒 Files selected for processing (24)
  • src/main/bitbucket/bitbucket-auth-config.ts
  • src/main/bitbucket/client.ts
  • src/main/bitbucket/credential-connection.test.ts
  • src/main/bitbucket/credential-connection.ts
  • src/main/bitbucket/credential-store.test.ts
  • src/main/bitbucket/credential-store.ts
  • src/main/bitbucket/status-no-decrypt.test.ts
  • src/main/bitbucket/user-request.ts
  • src/main/integration-credential-file.ts
  • src/main/ipc/bitbucket.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/bitbucket-credentials-dialog.tsx
  • src/renderer/src/components/settings/bitbucket-integration-card.tsx
  • src/renderer/src/components/settings/source-control-integration-cards.tsx
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/integration-credential-errors.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx

Comment thread src/main/bitbucket/credential-store.ts Resolved
Comment thread src/main/bitbucket/credential-store.ts Resolved
@devatnull

Copy link
Copy Markdown
Contributor

this is a needed feature

@nwparker

Copy link
Copy Markdown
Contributor Author

this is a needed feature

Sorry just got buried

If I cut an adhoc release, can you give it a spin? I'm not much of a bitbucket person 🥹

@devatnull

Copy link
Copy Markdown
Contributor

Yes, I can check, We use bitbucket everything unfortunately. On latest stable release even when via launchctl the vars are added and it marks it correctly, on a bitbucket repo it says "Pull request not supported here
This repository provider does not support creating a pull request from Orca."

Will check it along with your adhoc release.

…ntial storage

Bitbucket Cloud was the only review provider with no in-app auth: GitHub and
GitLab delegate to the gh/glab CLIs, but Bitbucket has no comparable
first-party CLI, so the only option was ORCA_BITBUCKET_* env vars plus a
restart (discussion #5364).

Adds a Connect/Edit/Disconnect flow on the Bitbucket integration card,
modeled on Linear and Jira:

- Credentials are verified against /user before they are persisted, so a
  dead token is rejected inline instead of silently stored.
- The secret is encrypted with safeStorage (0600 plaintext fallback when no
  OS keyring); non-secret metadata lives in a separate plaintext file so
  status reads render the connected account without decrypting. Opening
  Settings therefore never triggers a keychain prompt.
- Env vars keep precedence over stored credentials, so existing headless and
  SSH setups are unaffected. Env-managed connections hide Disconnect.
- connect/disconnect reset the preflight cache, so no relaunch is needed.

The Bitbucket card moves to its own file to stay under the tsx max-lines cap.
@nwparker
nwparker force-pushed the nwparker/bitbucket-disc branch from a769ab7 to 1b7e15f Compare August 11, 2026 08:03
@nwparker
nwparker requested a review from brennanb2025 as a code owner August 11, 2026 08:03
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker nwparker changed the title feat(bitbucket): in-app credential storage with keychain-backed Settings UI feat(bitbucket): connect Bitbucket from Settings with encrypted credential storage Aug 11, 2026
@nwparker

Copy link
Copy Markdown
Contributor Author

@devatnull thanks for the nudge — I rebuilt this on current main (the old branch was ~3300 commits behind and conflicting) and it's green again.

Since you offered to try it: still very keen. I don't have a Bitbucket account, so the one thing I can't verify is a successful connection end to end. The parts I could prove are in the PR body — the dialog, the inline rejection of a bad token against the real API, and env-var precedence.

What would help most:

  1. Connect — Settings → Integrations → Bitbucket → Connect → Email + API token (create one). Card should flip to Connected with your account, no restart.
  2. PRs actually show up — open a worktree on a bitbucket.org remote with an open PR and confirm the PR + build status render.
  3. The keychain thing — quit, relaunch, open Settings a few times. You should not get an OS "allow access to keychain" prompt each time (at most once, when PR data is first fetched). This is the bit I most want a second pair of eyes on.
  4. Edit / Disconnect round-trip.

Also worth knowing: Bitbucket Server / Data Center is not covered — repo detection still hardcodes the bitbucket.org host. If that's what you're on, say so and I'll open a follow-up.

Happy to cut an adhoc build if that's easier than running from source — just say the word.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/renderer/src/components/settings/integrations-search.ts (1)

59-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Generate locale keys for the new strings.

Replace bitbucketDescription and bitbucketAccessToken with IDs generated from <filePath>:<text>. This catalog uses generated hash IDs for new renderer strings.

Based on learnings, generate locale keys as the first 10 characters of the SHA-1 hash of <filePath>:<text>, then validate the localization catalogs.

Also applies to: 92-93

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 48f4d6f4-b02a-4eb6-83bd-2ec33820af84

📥 Commits

Reviewing files that changed from the base of the PR and between 21d5ca6 and 1b7e15f.

📒 Files selected for processing (23)
  • src/main/bitbucket/bitbucket-auth-config.ts
  • src/main/bitbucket/client.ts
  • src/main/bitbucket/credential-connection.test.ts
  • src/main/bitbucket/credential-connection.ts
  • src/main/bitbucket/credential-store.test.ts
  • src/main/bitbucket/credential-store.ts
  • src/main/bitbucket/status-no-decrypt.test.ts
  • src/main/bitbucket/user-request.ts
  • src/main/global-fetch-call-site-audit.test.ts
  • src/main/integration-credential-file.ts
  • src/main/ipc/bitbucket.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/bitbucket-credentials-dialog.tsx
  • src/renderer/src/components/settings/bitbucket-integration-card.tsx
  • src/renderer/src/components/settings/integrations-search.ts
  • src/renderer/src/components/settings/source-control-integration-cards.tsx
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/bitbucket-credentials.ts
  • src/shared/integration-credential-errors.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/main/ipc/register-core-handlers.ts
  • src/renderer/src/components/settings/source-control-integration-cards.tsx
  • src/shared/integration-credential-errors.ts
  • src/preload/index.ts
  • src/main/bitbucket/bitbucket-auth-config.ts
  • src/main/ipc/bitbucket.ts
  • src/main/integration-credential-file.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/bitbucket/credential-connection.test.ts

Comment thread src/main/bitbucket/credential-store.ts Resolved
@devatnull

Copy link
Copy Markdown
Contributor

Happy to cut an adhoc build if that's easier than running from source — just say the word.

Yes please, an ad-hoc macOS arm64 build would be easiest. Send the artifact and I will test it against my Bitbucket cloud.

Bitbucket was the only configured provider whose Create button reported
"This repository provider does not support creating a pull request from
Orca" — supportsReviewCreation was false and the forge provider had no
createReview, so even a correctly authenticated setup was blocked.

Adds createBitbucketPullRequest against POST /repositories/{ws}/{repo}/
pullrequests, using the same env-first / stored-credential resolution as PR
lookups (extracted into resolve-auth.ts so both share one path).

Bitbucket Cloud has no draft pull requests, so a draft request is rejected
with a clear message rather than silently publishing a live PR.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/source-control/forge-provider.test.ts (1)

167-202: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a Bitbucket delegate test.

This assertion only verifies supportsReviewCreation. It does not verify that createReview calls createBitbucketPullRequest. Add a mocked Bitbucket creation handler and assert its arguments and result, as this file already does for the other providers.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e9989262-4f2e-462d-abd2-b7c588a6aafe

📥 Commits

Reviewing files that changed from the base of the PR and between 1b7e15f and 3d4183f.

📒 Files selected for processing (6)
  • src/main/bitbucket/client.ts
  • src/main/bitbucket/pull-request-creation.test.ts
  • src/main/bitbucket/pull-request-creation.ts
  • src/main/bitbucket/resolve-auth.ts
  • src/main/source-control/forge-provider.test.ts
  • src/main/source-control/forge-provider.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/bitbucket/client.ts

Comment thread src/main/bitbucket/resolve-auth.ts Resolved
@nwparker

Copy link
Copy Markdown
Contributor Author

Also hold up, my AI was dumb. It didn't build the adhoc release...
Let me work on that

@nwparker

Copy link
Copy Markdown
Contributor Author

@devatnull found your actual problem, and it wasn't your env vars — those were working fine.

Bitbucket was the only provider Orca could read PRs from but never create them. The code literally had creation turned off for Bitbucket while GitHub, GitLab, Azure DevOps and Gitea all had it. That's why you got "This repository provider does not support creating a pull request from Orca" even with everything configured correctly.

So this PR now does two things:

  1. Connect Bitbucket from Settings — no env vars, no restart (the original point of the PR)
  2. Create PRs on Bitbucket — the thing you were actually blocked on

Adhoc build, if you want to try it:

https://github.com/stablyai/orca-adhoc/releases/tag/v1.4.181-adhoc.20260811081913

Grab orca-macos-arm64.dmg (Apple Silicon) or orca-macos-x64.dmg (Intel). It's signed and notarized, so it should just open. It's a separate app from your normal Orca — your settings and workspaces carry over.

What I'd love you to check:

  1. Your existing launchctl env vars should still work untouched — they take priority over anything saved in the app. Worth confirming nothing regressed.
  2. Create a PR from a Bitbucket worktree. This is the big one. Previously impossible.
  3. Optionally, try the new flow: Settings → Integrations → Bitbucket → Connect, with your Atlassian email + an API token. You'd be able to drop the env vars entirely.
  4. If you connect via the app: quit, reopen, and open Settings a few times. You shouldn't get a macOS keychain prompt each time.

Two things I already know:

  • No draft PRs. Bitbucket Cloud's API has no such thing, so if you tick Draft you'll get a clear error instead of Orca quietly opening a live PR. Uncheck it and it works.
  • Bitbucket Server / Data Center isn't supported — Cloud only right now. Tell me if that's what you're on and I'll sort it out separately.

I don't have a Bitbucket account, so you'd be the first person to run this against a real one. Any failure, paste what you see and I'll fix it.

… review fixes

Bitbucket Cloud has no draft pull requests, so the composer no longer offers
the toggle for it and forces the flag off at submit — better than failing
after the user has filled the form in.

Review fixes:
- writeFileSync's `mode` only applies when it creates the file, so rewriting
  a credential kept whatever permissions it already had. chmod after every
  write, for the secret and the metadata.
- An explicit ORCA_BITBUCKET_API_BASE_URL now wins over a stored base URL.
  Env precedence is per-setting, not all-or-nothing.
- Enter in the credentials dialog only submits from a text field, so it no
  longer hijacks Cancel and the docs link.
- Replace the chmod-based delete-failure test with a mocked unlinkSync: file
  modes are not portable to Windows and elevated runners unlink anyway.
@devatnull

Copy link
Copy Markdown
Contributor

I will add issues as I encounter:

1st: even when a PR status is merged it blocks from creating new PRs.

"Pull request already exists
Orca found an existing pull request for this branch." But the PR already looks as merged.

@nwparker

Copy link
Copy Markdown
Contributor Author

@devatnull use this build instead — I fixed a few things since the last one:

https://github.com/stablyai/orca-adhoc/releases/tag/v1.4.181-adhoc.20260811083442

orca-macos-arm64.dmg (Apple Silicon) or orca-macos-x64.dmg (Intel). Signed and notarized, so it opens normally. Separate app from your usual Orca; settings and workspaces carry over.

Changed since the last build: the Draft checkbox is now hidden for Bitbucket instead of erroring when you tick it, credential file permissions get re-tightened on reconnect, and ORCA_BITBUCKET_API_BASE_URL is honoured even when the credential is saved in the app.

The main thing to try: create a PR from a Bitbucket worktree. That was impossible before regardless of your env vars — Bitbucket was the only provider with PR creation switched off in the code, which is what produced that "does not support creating a pull request" message you saw.

Your launchctl vars still take priority over anything saved in the app, so nothing should regress there. Optionally you can drop them entirely now: Settings → Integrations → Bitbucket → Connect, with your Atlassian email + an API token.

Still Cloud only — no Bitbucket Server / Data Center. Tell me if that's what you're on.

Anything breaks, paste the error and I'll fix it.

… next one

Reported on #5832: with a merged PR on a branch, Create reported "Pull
request already exists" and offered no way forward.

The branch lookup queries every PR state and returns the most recently
updated one, so a merged PR came back as the branch's current review and
eligibility blocked on it. Bitbucket only discarded such a match on the repo
default branch (#9171), while GitHub already drops any merged PR it matched
by branch alone — "a merged PR without an explicit link is just a historical
branch match, not implicit review context".

Applies that rule to Bitbucket. An explicitly linked review still resolves
through the linked-number fallback, so merging a PR Orca knows about keeps
showing it.
@devatnull

Copy link
Copy Markdown
Contributor

Same issue, sees an already merged PR and says:

"Pull request already exists
Orca found an existing pull request for this branch."

On a repo with no existing PRs(so the above issue isnt triggered) says:

"Pull request not supported here
This repository provider does not support creating a pull request from Orca."

git remote -v
git branch --show-current

origin  [email protected]:ORG/REPO.git(fetch)
origin  [email protected]:ORG/REPO.git(push)
staging

git remote get-url origin:

[email protected]:ORG/REPO.git

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/main/bitbucket/client.test.ts (1)

147-163: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise the explicit linked-number fallback.

The mock returns pull request 7 for every non-status request. Therefore, this test passes from the branch-list response and does not verify the fallback request for the explicitly linked pull request.

Return an empty or different branch-list result, return pull request 7 only for /pullrequests/7, and assert that the fallback request was made.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e619151-29a1-4c6e-a2fc-71f830d6bf28

📥 Commits

Reviewing files that changed from the base of the PR and between e6399ec and 979f9cd.

📒 Files selected for processing (2)
  • src/main/bitbucket/client.test.ts
  • src/main/bitbucket/client.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/bitbucket/client.ts

@devatnull

Copy link
Copy Markdown
Contributor

I use SSH for bitbucket, not http, could be related to SSH, but should work with both. if it reads the provider for http format and not ssh may cause the PR not supported for this provdier issue.

@nwparker

Copy link
Copy Markdown
Contributor Author

@devatnull good catch, that's a real bug and it wasn't fixed in the build you had. New one:

https://github.com/stablyai/orca-adhoc/releases/tag/v1.4.181-adhoc.20260811085802

What was happening: the branch lookup asks Bitbucket for pull requests in any state and takes the most recently updated one. So once your PR merged, that merged PR came back as the branch's current review, and Create refused to run because it thought one already existed.

GitHub already handles this — it drops a merged PR it matched only by branch name, on the grounds that it's history rather than an active review. Bitbucket only did that on the repo's default branch, never on feature branches. Now it does.

A PR that Orca created or that you opened from Orca stays linked, so it'll still show as merged on the card. It's only the "found it purely by branch name" case that gets dropped.

Keep them coming.

…list

Reported on #5832: on a Bitbucket repo with no existing PR, Create still
said "This repository provider does not support creating a pull request
from Orca", even after the forge provider gained createReview.

There are two capability lists. Enabling supportsReviewCreation on the forge
provider was necessary but not sufficient — the blocker and the whole
renderer read the separate shared list, which never included bitbucket.

Adds it, gives Bitbucket its own provider name so review copy stops saying
"GitHub", and asserts the two lists agree so they cannot drift apart again.
@nwparker

Copy link
Copy Markdown
Contributor Author

@devatnull the second one was a separate bug and you were right to call it out. Fixed:

https://github.com/stablyai/orca-adhoc/releases/tag/v1.4.181-adhoc.20260811091553

"On a repo with no existing PRs(so the above issue isnt triggered) says: Pull request not supported here"

There were two lists of "providers Orca can create a review on". I'd only updated the backend one, so PR creation worked while the UI still refused to offer it. The blocker and the whole right sidebar read a different shared list that never had Bitbucket in it. Added, plus a test that the two lists match so this can't drift again.

"I use SSH for bitbucket, not http, could be related to SSH"

Good instinct, but SSH is fine here — remote parsing has passing coverage for [email protected]:..., ssh://, and HTTPS. Your merged-PR error actually proves it: Orca had to detect the repo and find that PR to complain about it, and it did that from your SSH remote. So no need to chase that one.

One more thing I fixed while in there: Bitbucket was falling through to GitHub's copy, so some strings would have said "GitHub" on a Bitbucket repo.

This build should get you a working Create PR on both repos. If it fails, the error text is mapped per Bitbucket status code now, so whatever it says should point at the real cause — paste it and I'll take a look.

@nwparker

Copy link
Copy Markdown
Contributor Author

The one above is indeed the latest. Sorry for the rounds of iteration 😅
The AI is trying lol

@devatnull

Copy link
Copy Markdown
Contributor

Thanks for building this. I tested the Bitbucket flow and found that PR creation still was not working end to end. I fixed the remaining issues, and it is now working in my local build: PR creation succeeds, the new PR appears immediately, and it stays linked after it is closed or merged.

I opened a follow-up PR against your branch with the fixes and regression tests: #13795

I also addressed the outstanding localization and forge-provider review comments. The commits are separated so you can merge or cherry-pick them individually.

@nwparker

Copy link
Copy Markdown
Contributor Author

@devatnull merged your #13795 and cut a build off it:

https://github.com/stablyai/orca-adhoc/releases/tag/v1.4.181-adhoc.20260811105220

That's your fixes plus everything earlier in one app. Should be the first build where the whole flow works end to end rather than just further along than the last one.

Worth a sanity pass on your side since you know what broke before: create a PR, confirm it shows up right away, then merge or decline it and confirm the card still points at it.

Thanks for doing the legwork on this — you found four separate bugs the tests didn't, and the linking one was mine.

@devatnull

Copy link
Copy Markdown
Contributor

Looks good, no issues, can be merged to stable or based on the official schedule, thanks for the help

@nwparker nwparker changed the title feat(bitbucket): connect Bitbucket from Settings with encrypted credential storage feat(bitbucket): connect Bitbucket from Settings and create pull requests Aug 11, 2026
@nwparker

Copy link
Copy Markdown
Contributor Author

"Looks good, no issues, can be merged to stable or based on the official schedule"

Appreciate you sticking with it through five builds. You found four bugs the test suite didn't, and one of them was mine — that's the only reason this is actually working rather than just looking like it does.

I've updated the PR description to cover the full scope, since it grew from "store credentials" into "Bitbucket PR creation works at all", and credited your #13795. Green on CI and mergeable; I'll let it go through normal review.

… comment

notFoundIsNull arrived without the rationale its sibling flag carries, and
reads as a bare `true` at the only call site that opts in.
Two of these made the feature unusable in real setups:

- Create PR checked GitHub authentication for Bitbucket. isProviderAuthenticated
  fell through to isGitHubAuthenticated, which was unreachable while Bitbucket
  could not create reviews at all. Anyone with Bitbucket connected but no
  `gh auth login` got auth_required with no way forward.
- The draft flag was only gated in ChecksPanel, not the two SourceControl call
  sites. With "create as draft" saved as a default, the composer hides the
  toggle for Bitbucket, so the flag could not be cleared and creation failed
  every time. Bitbucket now ignores draft instead of rejecting it.

Also:
- Blocked-create copy said "GitHub is not authenticated. Run gh auth login" on
  Bitbucket repos, in both the main-process and renderer paths.
- A decryption failure resolved to an anonymous config and queried anyway; a
  private repo answers 404, which reads as "no pull request" and offers Create
  for a branch that already has one. Requests now fail closed.
- Hiding non-open implicit branch matches was too broad: a declined PR became
  permanently invisible off the default branch. Scoped to merged, restoring the
  default-branch rule (#9171) for the rest.
- A failed disconnect rejected unhandled and the card silently re-rendered as
  connected; a partial delete left the secret live in memory for the session.
- The credentials dialog refused to open on a remote runtime, so a local repo
  could never store a credential. Now only the storage note changes, matching
  the Jira dialog.
@nwparker
nwparker merged commit 63271a5 into main Aug 11, 2026
86 of 88 checks passed
@nwparker
nwparker deleted the nwparker/bitbucket-disc branch August 11, 2026 22:32
@nwparker

Copy link
Copy Markdown
Contributor Author

Merged as 63271a5. @devatnull thanks again — this landed because you tested it properly.

A final review pass before merge caught two more things that would have bitten you specifically:

  • Create PR was checking GitHub authentication for Bitbucket repos, so anyone with Bitbucket connected but no gh auth login would have been blocked. You have gh, which is why it worked for you.
  • If you'd had "create as draft" saved as a default, creation would have failed every time with no way to clear it — the toggle is hidden for Bitbucket. It now ignores the flag instead of erroring.

Both fixed, along with a few smaller ones: a decryption failure could query anonymously and report "no pull request" for a branch that has one, declined PRs were being hidden, and the credentials dialog wouldn't open at all on a remote runtime.

It'll be in the next build off main rather than an adhoc one. Open a fresh issue for anything else and tag me — Bitbucket Server / Data Center is still the obvious gap.

OrcaWin added a commit that referenced this pull request Aug 12, 2026
…pport

Bitbucket is a HostedReviewCreationProvider after #5832, so the
provider-unavailable case must use the unsupported sentinel. Keeps the
structural gate coverage and adds a positive bitbucket create assertion.

Unblocks Mobile Checks verify on #13977.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ests (stablyai#5832)

* feat(bitbucket): connect Bitbucket from Settings with encrypted credential storage

Bitbucket Cloud was the only review provider with no in-app auth: GitHub and
GitLab delegate to the gh/glab CLIs, but Bitbucket has no comparable
first-party CLI, so the only option was ORCA_BITBUCKET_* env vars plus a
restart (discussion stablyai#5364).

Adds a Connect/Edit/Disconnect flow on the Bitbucket integration card,
modeled on Linear and Jira:

- Credentials are verified against /user before they are persisted, so a
  dead token is rejected inline instead of silently stored.
- The secret is encrypted with safeStorage (0600 plaintext fallback when no
  OS keyring); non-secret metadata lives in a separate plaintext file so
  status reads render the connected account without decrypting. Opening
  Settings therefore never triggers a keychain prompt.
- Env vars keep precedence over stored credentials, so existing headless and
  SSH setups are unaffected. Env-managed connections hide Disconnect.
- connect/disconnect reset the preflight cache, so no relaunch is needed.

The Bitbucket card moves to its own file to stay under the tsx max-lines cap.

* feat(bitbucket): support creating pull requests from Orca

Bitbucket was the only configured provider whose Create button reported
"This repository provider does not support creating a pull request from
Orca" — supportsReviewCreation was false and the forge provider had no
createReview, so even a correctly authenticated setup was blocked.

Adds createBitbucketPullRequest against POST /repositories/{ws}/{repo}/
pullrequests, using the same env-first / stored-credential resolution as PR
lookups (extracted into resolve-auth.ts so both share one path).

Bitbucket Cloud has no draft pull requests, so a draft request is rejected
with a clear message rather than silently publishing a live PR.

* fix(bitbucket): hide the draft toggle where drafts do not exist, plus review fixes

Bitbucket Cloud has no draft pull requests, so the composer no longer offers
the toggle for it and forces the flag off at submit — better than failing
after the user has filled the form in.

Review fixes:
- writeFileSync's `mode` only applies when it creates the file, so rewriting
  a credential kept whatever permissions it already had. chmod after every
  write, for the secret and the metadata.
- An explicit ORCA_BITBUCKET_API_BASE_URL now wins over a stored base URL.
  Env precedence is per-setting, not all-or-nothing.
- Enter in the credentials dialog only submits from a text field, so it no
  longer hijacks Cancel and the docs link.
- Replace the chmod-based delete-failure test with a mocked unlinkSync: file
  modes are not portable to Windows and elevated runners unlink anyway.

* fix(bitbucket): stop a merged pull request from blocking the branch's next one

Reported on stablyai#5832: with a merged PR on a branch, Create reported "Pull
request already exists" and offered no way forward.

The branch lookup queries every PR state and returns the most recently
updated one, so a merged PR came back as the branch's current review and
eligibility blocked on it. Bitbucket only discarded such a match on the repo
default branch (stablyai#9171), while GitHub already drops any merged PR it matched
by branch alone — "a merged PR without an explicit link is just a historical
branch match, not implicit review context".

Applies that rule to Bitbucket. An explicitly linked review still resolves
through the linked-number fallback, so merging a PR Orca knows about keeps
showing it.

* fix(bitbucket): add bitbucket to the shared review-creation provider list

Reported on stablyai#5832: on a Bitbucket repo with no existing PR, Create still
said "This repository provider does not support creating a pull request
from Orca", even after the forge provider gained createReview.

There are two capability lists. Enabling supportsReviewCreation on the forge
provider was necessary but not sufficient — the blocker and the whole
renderer read the separate shared list, which never included bitbucket.

Adds it, gives Bitbucket its own provider name so review copy stops saying
"GitHub", and asserts the two lists agree so they cannot drift apart again.

* fix(bitbucket): persist pull request links after creation

* fix(bitbucket): fetch linked pull requests by number first

* fix(i18n): use generated Bitbucket integration keys

* test(bitbucket): cover forge creation delegation

* fix(bitbucket): fall back when linked pull request is stale

* docs(bitbucket): explain notFoundIsNull and fix a garbled permissions comment

notFoundIsNull arrived without the rationale its sibling flag carries, and
reads as a bare `true` at the only call site that opts in.

* fix(bitbucket): address review findings before merge

Two of these made the feature unusable in real setups:

- Create PR checked GitHub authentication for Bitbucket. isProviderAuthenticated
  fell through to isGitHubAuthenticated, which was unreachable while Bitbucket
  could not create reviews at all. Anyone with Bitbucket connected but no
  `gh auth login` got auth_required with no way forward.
- The draft flag was only gated in ChecksPanel, not the two SourceControl call
  sites. With "create as draft" saved as a default, the composer hides the
  toggle for Bitbucket, so the flag could not be cleared and creation failed
  every time. Bitbucket now ignores draft instead of rejecting it.

Also:
- Blocked-create copy said "GitHub is not authenticated. Run gh auth login" on
  Bitbucket repos, in both the main-process and renderer paths.
- A decryption failure resolved to an anonymous config and queried anyway; a
  private repo answers 404, which reads as "no pull request" and offers Create
  for a branch that already has one. Requests now fail closed.
- Hiding non-open implicit branch matches was too broad: a declined PR became
  permanently invisible off the default branch. Scoped to merged, restoring the
  default-branch rule (stablyai#9171) for the rest.
- A failed disconnect rejected unhandled and the card silently re-rendered as
  connected; a partial delete left the secret live in memory for the session.
- The credentials dialog refused to open on a remote runtime, so a local repo
  could never store a credential. Now only the storage note changes, matching
  the Jira dialog.

---------

Co-authored-by: devatnull <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants