Skip to content

feat(integrations): add Bitbucket Cloud - #6860

Merged
waleedlatif1 merged 6 commits into
stagingfrom
feature/bitbucket-integration
Aug 20, 2026
Merged

feat(integrations): add Bitbucket Cloud#6860
waleedlatif1 merged 6 commits into
stagingfrom
feature/bitbucket-integration

Conversation

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor

Summary

Adds a complete Bitbucket Cloud action integration with 30 OAuth-backed tools for repository/source inspection, pull request collaboration, and pipeline operations.

Includes:

  • Bitbucket OAuth provider/configuration and self-hosted setup docs
  • Bitbucket block with workspace/repository cascading selectors
  • Structured, fail-closed request/response normalization, bounded raw reads, strict cursor binding, and safe retry behavior
  • Generated tool metadata, integration catalog entries, icons, and action documentation

No triggers or webhooks are included.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other

Testing

  • bunx vitest run app/api/tools/bitbucket hooks/selectors/providers/bitbucket blocks/blocks/bitbucket.test.ts tools/bitbucket — 323 tests passed
  • bun run tool-metadata:check
  • bun run check:tool-registry-boundary
  • bun run apps/sim/scripts/check-canvas-sentences.ts --block=bitbucket — 30/30 operations
  • bun run check:bare-icons
  • bun run integration-catalog:check
  • bun run docs:check
  • bun run check:api-validation
  • bun run type-check
  • git diff --check

Reviewer focus:

  • OAuth provider mapping and rotating-token persistence behavior
  • Bitbucket-specific cursor/redirect validation and bounded raw-content handling
  • Normalized nullable collection semantics and mutation input validation

Known follow-ups intentionally outside this PR:

  • Shared multi-replica rotating-refresh coordination requires a separate provider-agnostic PR.
  • Bitbucket's merge request-body type discriminator needs a disposable live-provider probe before adding an undocumented value.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

Not applicable; no standalone visual workflow changes.

@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 20, 2026 3:25am

Request Review

@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Large new integration with OAuth and mutating APIs (merge/decline PRs, branch delete, pipeline trigger/stop), but mutations follow existing fail-closed credential and cursor-validation patterns rather than changing core auth.

Overview
Introduces a new Bitbucket Cloud action integration (OAuth only—no triggers or webhooks) so workflows can inspect repos and source, collaborate on pull requests, and run or diagnose pipelines.

The surface area is 30 registered tools (workspaces through pipeline step logs), a workflow block with operation-specific fields, cascading workspace/repository pickers, and server routes that authorize credentials, refresh tokens, and call Bitbucket with strict API cursor validation (host/path/workspace binding, no redirects) plus bounded JSON and raw reads.

OAuth is wired end-to-end: consumer config env vars, connector registration (basic-auth token exchange), self-hosted docs with required consumer permissions, connect-modal scope text keyed by provider, and catalog/docs/icons for the integration page.

Supporting tests cover block↔tool mapping, selector hooks, and repository/workspace API routes (auth order, malformed provider responses, cursor rejection).

Reviewed by Cursor Bugbot for commit f5cf56c. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a Bitbucket Cloud OAuth integration with repository, source, pull-request, and pipeline actions.

  • Registers Bitbucket OAuth configuration, deployment capabilities, selectors, block metadata, and documentation.
  • Adds 30 tools with normalized outputs, mutation validation, cursor binding, redirect controls, bounded raw-content reads, and retry handling.
  • Adds focused tests for OAuth behavior, selectors, block configuration, repository/source operations, pull requests, and pipelines.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/auth/connectors/providers.ts Registers Bitbucket as a connector-only OAuth provider with Basic-auth token exchange and scoped user-info retrieval.
apps/sim/lib/oauth/oauth.ts Adds Bitbucket refresh configuration and rotating refresh-token handling through the existing credential persistence path.
apps/sim/app/api/tools/bitbucket/workspaces/route.ts Adds an authenticated, credential-authorized workspace selector endpoint with validated pagination.
apps/sim/app/api/tools/bitbucket/repositories/route.ts Adds a credential-authorized repository selector endpoint scoped to a validated workspace.
apps/sim/blocks/blocks/bitbucket.ts Defines the Bitbucket block’s 30 operations, cascading selectors, parameter mappings, outputs, and canvas presentation.
apps/sim/tools/bitbucket/utils.ts Implements shared URL binding, response normalization, pagination, and bounded byte-reading utilities.
apps/sim/tools/bitbucket/utils.server.ts Implements pinned secure reads, constrained redirect resolution, retry behavior, and response-size protections.
apps/sim/tools/registry.ts Registers all new Bitbucket tools for generic workflow dispatch.

Sequence Diagram

sequenceDiagram
  participant User as Workflow user
  participant Block as Bitbucket block
  participant Selector as Selector API
  participant OAuth as OAuth credential service
  participant Tool as Bitbucket tool
  participant BB as Bitbucket Cloud

  User->>Block: Configure operation
  Block->>Selector: Load workspaces/repositories
  Selector->>OAuth: Authorize credential use
  OAuth-->>Selector: Access token
  Selector->>BB: Fetch selector options
  BB-->>Selector: Paginated resources
  Selector-->>Block: Normalized options
  User->>Block: Execute operation
  Block->>Tool: Mapped operation parameters
  Tool->>OAuth: Resolve or refresh token
  OAuth-->>Tool: Valid access token
  Tool->>BB: Validated API request
  BB-->>Tool: API/raw response
  Tool-->>Block: Bounded normalized output
Loading

Reviews (3): Last reviewed commit: "fix(bitbucket): stop advanced-field leak..." | Re-trigger Greptile

Comment thread apps/sim/app/api/tools/bitbucket/repositories/route.ts
Comment thread apps/sim/app/api/tools/bitbucket/workspaces/route.ts
Comment thread apps/sim/tools/bitbucket/utils.ts
Comment thread apps/sim/tools/bitbucket/trigger_pipeline.ts
…nd selector paths

Splits the `closeSourceBranch` advanced subBlock into per-operation ids. Advanced
fields serialize without evaluating their condition, so a value set on Create Pull
Request reached Merge Pull Request and closed the source branch unprompted.

Also:
- read step logs through the byte-capped server transport and map an empty-log 416
  to an empty result, keeping a genuine 416 an error
- trim a step log's partial leading line after the character cap rather than before,
  and never return an empty log when the retained window held content
- surface Bitbucket's `error.detail` alongside `error.message`
- treat commit-status `key`/`state` as nullable so one malformed row cannot drop a page
- match repository `full_name` case-insensitively and reject dot segments in a
  workspace slug before the outbound request
- type `reviewerAccountIds` as the comma-separated string it is
- trim optional Bitbucket query strings; correct the token lifetime to two hours
@waleedlatif1

Copy link
Copy Markdown
Collaborator

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d226be6. Configure here.

@waleedlatif1
waleedlatif1 merged commit e3a4874 into staging Aug 20, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the feature/bitbucket-integration branch August 20, 2026 03:32
@waleedlatif1

Copy link
Copy Markdown
Collaborator

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d226be6. Configure here.

}
} else if (candidatePath.replace(/\/$/, '') !== exactPath) {
throw new Error('nextUrl does not belong to this Bitbucket list endpoint')
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Case-sensitive Bitbucket path binding

Medium Severity

Workspace and repository slugs are bound with exact pathname equality in bitbucketApiUrl, validateBitbucketPullRequestRedirect, and mergeTaskLocation, while Bitbucket and the repository selector treat those slugs as case-insensitive. A mixed-case workspaceSlug or repoSlug still works on the first request, but provider next links, PR diff/diffstat Location headers, and async merge task URLs typically use the canonical lowercase path, so pagination and post-merge polling throw even though Bitbucket accepted the original request. A failed merge-task parse after 202 is especially painful because the merge may already have started.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d226be6. Configure here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Real bug, fixed in 5fb1ae5.

Bitbucket resolves workspace and repository slugs case-insensitively but echoes the canonical lowercase form back, so exact string equality broke every follow-up request after a mixed-case slug succeeded on the first one. All three sites now compare case-insensitively via a shared equalsIgnoreCase helper:

  • bitbucketApiUrl — both the exact-path branch and the nextPathPrefix segment comparison, plus nextRevision (hex SHAs are case-insensitive by definition, and requireBitbucketSha1 already accepts uppercase)
  • validateBitbucketPullRequestRedirect — prefix match only; the opaque spec after the prefix is still sliced from the original pathname verbatim
  • mergeTaskLocation — same, with the task id decoded from the untouched pathname

Repository file paths deliberately keep verbatim comparison — git treats those as case-sensitive, so src/Dir must not match src/dir. There is a test asserting exactly that alongside the mixed-case acceptance cases, in utils.test.ts and pull-requests.test.ts.

Worth noting the same class of bug was independently found and fixed in the repository selector route in the previous commit (full_name prefix match); this closes it in the tool layer too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Correction to my previous reply: this PR was squash-merged as e3a4874 while the fix was in progress, so commit 5fb1ae5 is not part of the merge. The fix now ships as #6883 against staging instead. Everything described above is accurate about that PR, not this one.

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