Skip to content

Bitbucket - Add Bitbucket Integration#4218

Open
eshurakov wants to merge 1 commit into
mainfrom
earthy-giant
Open

Bitbucket - Add Bitbucket Integration#4218
eshurakov wants to merge 1 commit into
mainfrom
earthy-giant

Conversation

@eshurakov

@eshurakov eshurakov commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add personal and organization-owned Bitbucket Cloud OAuth connections with encrypted credential storage, workspace selection, repository caching, and GDPR cleanup.
  • Resolve Bitbucket contributor repositories and short-lived credentials through git-token-service, with live owner authorization checks and purpose-bound internal tokens.
  • Extend Cloud Agent session admission, persistence, clone, resume, and push flows to support stable Bitbucket workspace and repository identities.
  • Add Web integration management and repository selection, plus the database migration and production Worker configuration required for deployment.

Verification

  • Tested locally with Cloud Agent
Screenshot 2026-06-23 at 23 24 30

@eshurakov eshurakov changed the title feat(bitbucket): add Cloud Agent integration Bitbucket - Add Bitbucket Integration Jun 23, 2026
const onlyAvailableRepo =
!isLoadingGitHubRepos &&
!isLoadingGitLabRepos &&
(organizationId || !isLoadingBitbucketRepos) &&

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.

WARNING: Repository auto-selection can race Bitbucket loading

For personal sessions this effect still runs while the Bitbucket query is loading, and for organization sessions organizationId || !isLoadingBitbucketRepos explicitly treats the repository set as complete before Bitbucket finishes. Because getPreferredInitialRepo() still only tracks GitHub/GitLab loading, a saved or recent GitHub/GitLab repo can be auto-selected here and prevent the user’s Bitbucket repo from ever being chosen automatically.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

CREATE UNIQUE INDEX "UQ_platform_oauth_credentials_platform_integration_id" ON "platform_oauth_credentials" USING btree ("platform_integration_id");--> statement-breakpoint
CREATE INDEX "IDX_platform_oauth_credentials_platform_subject" ON "platform_oauth_credentials" USING btree ("platform","provider_subject_id");--> statement-breakpoint
CREATE INDEX "IDX_platform_oauth_credentials_authorized_by_user_id" ON "platform_oauth_credentials" USING btree ("authorized_by_user_id");--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_platform_integrations_user_bitbucket" ON "platform_integrations" USING btree ("owned_by_user_id","platform") WHERE "platform_integrations"."platform" = 'bitbucket' AND "platform_integrations"."owned_by_user_id" IS NOT NULL;--> statement-breakpoint

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.

WARNING: Non-concurrent index creation can block writes on deploy

platform_integrations is an existing populated table, so these two CREATE UNIQUE INDEX statements will take a write-blocking lock while the migration runs. In production that can stall integration updates and other writes; this needs a concurrent rollout strategy instead of plain index creation.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/db/src/migrations/0173_wealthy_johnny_blaze.sql 49 New indexes on populated platform_integrations are created without CONCURRENTLY, which can block writes during deploy.
apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx 529 Bitbucket loading can still race repository auto-selection and lock in the wrong saved/recent repo.
apps/web/src/components/shared/RepositoryCombobox.tsx 21 Bitbucket selections are persisted but never restored because last-used repo parsing still rejects platform: "bitbucket".
Files Reviewed (136 files)
  • packages/db/src/migrations/0173_wealthy_johnny_blaze.sql - 1 issue
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx - 1 issue
  • apps/web/src/components/shared/RepositoryCombobox.tsx - 1 issue
  • 133 additional changed files - 0 issues
Previous Review Summaries (3 snapshots, latest commit d876fd8)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d876fd8)

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx 530 Bitbucket loading can race repository auto-selection and lock in the wrong saved/recent repo.
packages/db/src/migrations/0173_handy_silver_samurai.sql 51 New indexes on populated platform_integrations are created without CONCURRENTLY, which can block writes during deploy.
Files Reviewed (136 files)
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx - 1 issue
  • packages/db/src/migrations/0173_handy_silver_samurai.sql - 1 issue
  • 134 additional changed files - 0 issues

Previous review (commit eb72ecd)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • apps/web/src/components/cloud-agent-next/utils/git-utils.ts
  • apps/web/src/lib/token.test.ts
  • apps/web/src/lib/tokens.ts

Previous review (commit 95af145)

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx 530 Bitbucket loading can race repository auto-selection and lock in the wrong saved/recent repo.
packages/db/src/migrations/0173_cynical_the_executioner.sql 25 New indexes on populated platform_integrations are created without CONCURRENTLY, which can block writes during deploy.
Files Reviewed (103 files)
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx - 1 issue
  • packages/db/src/migrations/0173_cynical_the_executioner.sql - 1 issue
  • 101 additional changed files - 0 issues

Reviewed by gpt-5.4-20260305 · Input: 420.5K · Output: 28.5K · Cached: 2.4M

Review guidance: REVIEW.md from base branch main

Includes Bitbucket OAuth setup, repository selection support, token-service integration, worker secret handling, and organization Workspace Access Token authorization.
const onlyAvailableRepo =
!isLoadingGitHubRepos &&
!isLoadingGitLabRepos &&
(!organizationId || !isLoadingBitbucketRepos) &&

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.

WARNING: Repository auto-selection can still beat Bitbucket loading

This effect now waits for Bitbucket before using the single-repo fallback, but getPreferredInitialRepo() still only tracks GitHub/GitLab loading. When a saved or recent GitHub/GitLab repo is already in unifiedRepositories, it can be auto-selected before Bitbucket finishes loading and prevent the intended Bitbucket repo from ever being chosen automatically.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

import { BitbucketLogo } from '@/components/auth/BitbucketLogo';

export type RepositoryPlatform = 'github' | 'gitlab';
export type RepositoryPlatform = 'github' | 'gitlab' | 'bitbucket';

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.

WARNING: Saved Bitbucket repo preference is discarded on reload

Now that RepositoryPlatform includes bitbucket, setLastUsedRepo() can persist platform: "bitbucket" for org sessions, but parseLastUsedRepo() in model-preferences.ts still only accepts GitHub and GitLab. Reloading the panel drops the saved Bitbucket repo, so the new provider never benefits from last-used repo auto-selection.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

CREATE UNIQUE INDEX "UQ_platform_oauth_credentials_platform_integration_id" ON "platform_oauth_credentials" USING btree ("platform_integration_id");--> statement-breakpoint
CREATE INDEX "IDX_platform_oauth_credentials_platform_subject" ON "platform_oauth_credentials" USING btree ("platform","provider_subject_id");--> statement-breakpoint
CREATE INDEX "IDX_platform_oauth_credentials_authorized_by_user_id" ON "platform_oauth_credentials" USING btree ("authorized_by_user_id");--> statement-breakpoint
CREATE UNIQUE INDEX "UQ_platform_integrations_user_bitbucket" ON "platform_integrations" USING btree ("owned_by_user_id","platform") WHERE "platform_integrations"."platform" = 'bitbucket' AND "platform_integrations"."owned_by_user_id" IS NOT NULL;--> statement-breakpoint

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.

WARNING: Non-concurrent unique indexes can block writes on deploy

platform_integrations is an existing populated table, so these CREATE UNIQUE INDEX statements will take write-blocking locks while the migration runs. In production that can stall integration updates and other writes; this needs a concurrent rollout strategy instead of plain index creation.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

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.

1 participant