Skip to content

Add Bitbucket support #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 25, 2025
Merged

Add Bitbucket support #275

merged 15 commits into from
Apr 25, 2025

Conversation

msukkari
Copy link
Contributor

@msukkari msukkari commented Apr 24, 2025

Adds support for pulling repos from Bitbucket Cloud and Bitbucket Data Center

Thanks @stevealx for the initial implementation #143. This PR builds ontop of that to support the integration with v3 changes

Summary by CodeRabbit

  • New Features

    • Added support for connecting to Bitbucket Cloud and Bitbucket Data Center, enabling repository syncing and indexing from both platforms.
    • Introduced dedicated connection creation forms, quick actions, and authentication flows for Bitbucket integrations.
    • Bitbucket repositories can now be included or excluded by workspace, project, repository, archived/forked status, and revision filters.
    • Bitbucket is now available as a selectable code host during onboarding and in connection management.
  • Documentation

    • Added comprehensive guides for configuring Bitbucket Cloud and Bitbucket Data Center connections, including authentication instructions and schema references.
    • Updated documentation and UI to reflect Bitbucket as a supported code host.
  • Bug Fixes

    • Improved URL placeholder handling in code preview links for more accurate navigation.
  • Chores

    • Updated changelog to reflect Bitbucket support.
    • Added Bitbucket SDK as a dependency.

Copy link

coderabbitai bot commented Apr 24, 2025

Walkthrough

This change introduces comprehensive support for Bitbucket Cloud and Bitbucket Data Center (Server) as code host integrations. It includes backend logic for Bitbucket repository discovery, schema and type definitions for configuration, and robust error handling. The web application is updated to allow users to create, configure, and manage Bitbucket connections via new forms, quick actions, and onboarding flows. Documentation is expanded with new guides, authentication instructions, and schema references for Bitbucket integrations. The package manifest is updated to include the Bitbucket SDK dependency, and relevant UI components and event tracking are extended to support Bitbucket types across the platform.

Changes

Files/Paths Change Summary
docs/docs/connections/bitbucket-cloud.mdx, docs/docs/connections/bitbucket-data-center.mdx Added new documentation pages for Bitbucket Cloud and Bitbucket Data Center, including configuration examples, authentication instructions, and schema references.
docs/snippets/bitbucket-app-password.mdx, docs/snippets/bitbucket-token.mdx Added documentation snippets explaining Bitbucket authentication setup using app passwords and tokens, with environment variable and secret-based configuration examples.
docs/docs/overview.mdx, docs/docs/connections/overview.mdx, docs/self-hosting/overview.mdx Updated documentation and self-hosting guides to include Bitbucket Cloud and Data Center as supported code hosts, adding corresponding icons and links.
docs/snippets/connection-cards.mdx Deleted the old connection cards snippet, previously listing GitHub and GitLab only.
docs/docs.json Updated documentation navigation to include Bitbucket Cloud and Data Center connection pages.
CHANGELOG.md Added an entry noting support for Bitbucket Cloud and Bitbucket Data Center in the unreleased section.
package.json Added @coderabbitai/bitbucket as a dependency.
packages/backend/src/bitbucket.ts Added new Bitbucket integration client with support for Cloud and Server, including repository fetching, filtering, and error handling.
packages/backend/src/repoCompileUtils.ts Added compileBitbucketConfig to process Bitbucket connection configs and map Bitbucket repositories to internal format.
packages/backend/src/connectionManager.ts Integrated Bitbucket connection support into the connection manager's sync logic.
packages/backend/src/repoManager.ts Refactored authentication logic to support Bitbucket, updating token handling and username/password assignment for all code hosts. Improved logging for job retries and garbage collection.
packages/schemas/src/v3/bitbucket.schema.ts, schemas/v3/bitbucket.json Introduced new JSON schema for Bitbucket connection configuration, defining all available fields, validation, and conditional requirements.
packages/schemas/src/v3/bitbucket.type.ts, packages/schemas/src/v3/index.type.ts Added BitbucketConnectionConfig and related types/interfaces for Bitbucket connection configuration, including support for authentication, filtering, and revision selection.
packages/schemas/src/v3/connection.schema.ts, packages/schemas/src/v3/index.schema.ts Added Bitbucket connection schema to the union of supported connection types, enabling validation and configuration for Bitbucket in the system.
schemas/v3/connection.json Added Bitbucket connection schema reference to the JSON schema for connection configs.
packages/web/src/lib/utils.ts Updated code host utilities to recognize and display Bitbucket Cloud and Server, including icons and authentication support.
packages/web/src/actions.ts Refactored connection config parsing to support Bitbucket, updating schema selection and validation logic.
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx, .../bitbucketDataCenterConnectionCreationForm.tsx Added new React components for Bitbucket Cloud and Data Center connection creation forms, including validation and quick actions.
packages/web/src/app/[domain]/components/connectionCreationForms/index.ts Exported new Bitbucket connection creation form components.
packages/web/src/app/[domain]/connections/components/newConnectionCard.tsx Added Bitbucket Cloud and Data Center as selectable cards for new connections.
packages/web/src/app/[domain]/connections/new/[type]/page.tsx Added conditional rendering for Bitbucket connection creation forms based on type.
packages/web/src/app/[domain]/connections/quickActions.tsx Added quick action sets for Bitbucket Cloud and Data Center, including workspace, project, repo, and exclusion helpers.
packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx Extended onboarding to support Bitbucket Cloud and Data Center, updating selection UI and onboarding event tracking.
packages/web/src/lib/posthogEvents.ts Added onboarding event types for Bitbucket Cloud and Server selection.
packages/web/src/app/[domain]/components/importSecretDialog.tsx Added support for Bitbucket Cloud and Data Center in secret import dialog, with new PAT creation steps and updated secret key placeholder.
packages/web/src/app/[domain]/connections/[id]/components/configSetting.tsx Added Bitbucket Cloud and Server support to the connection config settings UI, with type-safe props and quick actions.
packages/web/src/app/[domain]/connections/[id]/page.tsx Updated to cast connection type as CodeHostType for config settings.
packages/web/src/app/[domain]/components/codeHostIconButton.tsx Increased button size and centered label for code host icon buttons.
packages/web/src/app/[domain]/search/components/codePreviewPanel/index.tsx Improved URL template parsing to substitute branch and path placeholders in query parameters.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebApp
    participant Backend
    participant BitbucketAPI

    User->>WebApp: Initiate Bitbucket Connection (Cloud or Server)
    WebApp->>WebApp: Show Bitbucket Connection Form
    User->>WebApp: Submit Connection Config (with auth, workspaces/projects/repos)
    WebApp->>Backend: Send Connection Config
    Backend->>BitbucketAPI: Authenticate and Fetch Repositories (paginated)
    BitbucketAPI-->>Backend: Return Repository Data
    Backend->>Backend: Filter/Exclude Repos per Config
    Backend-->>WebApp: Return Valid/NotFound Repos
    WebApp->>User: Show Connection Status and Repo List
Loading

Suggested reviewers

  • brendan-kellam

Poem

Hopping through the code, what do I see?
Bitbucket joins the warren—cloud and DC!
New docs and forms, quick actions in tow,
Repos and secrets, all ready to go.
With icons and schemas, the garden expands—
This rabbit’s delighted by these clever hands!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🧹 Nitpick comments (8)
packages/web/src/app/[domain]/search/components/codePreviewPanel/index.tsx (1)

68-72: Consider using regex to replace all occurrences of placeholders

The current implementation only replaces the first occurrence of each placeholder because the standard replace method only replaces the first match. If there are multiple occurrences of these placeholders in the query parameters, only the first will be replaced.

Consider using regex with global flag to ensure all occurrences are replaced:

const optionalQueryParams = 
    template.substring(template.indexOf("}}") + 2)
-   .replace("{{.Version}}", branch ?? "HEAD")
-   .replace("{{.Path}}", fileMatch.FileName);
+   .replace(/{{\.Version}}/g, branch ?? "HEAD")
+   .replace(/{{\.Path}}/g, fileMatch.FileName);
docs/snippets/bitbucket-app-password.mdx (1)

1-51: Well-structured documentation for Bitbucket app password authentication

The documentation snippet provides clear instructions for configuring Bitbucket app password authentication with both environment variable and secret approaches. The tabbed interface, step-by-step instructions, and example configurations are helpful.

One minor note: The JSON examples include JavaScript-style comments (//), which aren't valid in actual JSON. Consider mentioning that these are explanatory comments that should be removed in actual configuration files, or use a different comment syntax that works with your documentation framework.

docs/snippets/bitbucket-token.mdx (1)

1-47: Clear documentation for Bitbucket token configuration

The token authentication documentation is well-organized with appropriate tabbed sections for different authentication methods. The explanations are clear and the examples illustrate the configuration patterns effectively.

As with the app password snippet, the JSON examples include comments that aren't valid in standard JSON. Consider adding a note that these comments are for documentation purposes only and should be removed in actual configuration files.

docs/docs/connections/bitbucket-server.mdx (1)

65-66: Consider simplifying the wording

The phrase "In order to" can be simplified for better readability.

-In order to index private repositories, you'll need to provide an access token to Sourcebot.
+To index private repositories, you'll need to provide an access token to Sourcebot.
docs/docs/connections/bitbucket-cloud.mdx (1)

73-73: Improve wording for conciseness.

Consider simplifying the opening phrase for better readability.

-In order to index private repositories, you'll need to provide authentication credentials. You can do this using an `App Password` or an `Access Token`
+To index private repositories, provide authentication credentials using either an `App Password` or an `Access Token`
packages/backend/src/repoCompileUtils.ts (1)

356-373: Simplify web URL extraction logic.

The web URL extraction contains complex type casting and conditionals that could be simplified for better readability.

 const getWebUrl = (repo: BitbucketRepository) => {
     const isServer = config.deploymentType === 'server';
-    const repoLinks = (repo as BitbucketServerRepository | BitbucketCloudRepository).links;
-    const repoName = isServer ? (repo as BitbucketServerRepository).name : (repo as BitbucketCloudRepository).full_name;
+    const repoLinks = repo.links;
+    const repoName = isServer ? 
+        (repo as BitbucketServerRepository).name : 
+        (repo as BitbucketCloudRepository).full_name;

     if (!repoLinks) {
         throw new Error(`No links found for ${isServer ? 'server' : 'cloud'} repo ${repoName}`);
     }

-    // In server case we get an array of lenth == 1 links in the self field, while in cloud case we get a single
+    // In server case we get an array of length == 1 links in the self field, while in cloud case we get a single
     // link object in the html field
     const link = isServer ? (repoLinks.self as { name: string, href: string }[])?.[0] : repoLinks.html as { href: string };
     if (!link || !link.href) {
         throw new Error(`No ${isServer ? 'self' : 'html'} link found for ${isServer ? 'server' : 'cloud'} repo ${repoName}`);
     }

     return link.href;
 }
packages/schemas/src/v3/index.schema.ts (1)

617-618: Verify URL example consistency.

The default URL is set to the Bitbucket API endpoint (https://api.bitbucket.org/2.0), but the example shows a non-API URL (https://bitbucket.example.com). Consider clarifying in the description that API endpoints should be used for the cloud deployment type.

-                  "description": "Bitbucket URL",
+                  "description": "Bitbucket URL. For cloud deployment, use the API endpoint.",
                   "examples": [
-                    "https://bitbucket.example.com"
+                    "https://api.bitbucket.org/2.0",
+                    "https://bitbucket-server.example.com/rest/api/1.0"
                   ],
packages/backend/src/repoManager.ts (1)

180-191: Remove redundant switch cases to reduce noise

Every case except "gitlab" falls through to the same default branch ('').
Keeping the extra cases adds eight useless branches and was flagged by Biome. A simple ternary – or an if for GitLab – is clearer and cheaper for the JS engine to optimise.

-        let username = (() => {
-            switch (repo.external_codeHostType) {
-                case 'gitlab':
-                    return 'oauth2';
-                case 'bitbucket-server':
-                case 'bitbucket-cloud':
-                case 'github':
-                case 'gitea':
-                default:
-                    return '';
-            }
-        })();
+        const username =
+            repo.external_codeHostType === 'gitlab'
+                ? 'oauth2'
+                : '';
🧰 Tools
🪛 Biome (1.9.4)

[error] 184-184: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 185-185: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 186-186: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 187-187: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c201a5e and 4c6636d.

⛔ Files ignored due to path filters (3)
  • docs/images/bitbucket_app_password_perms.png is excluded by !**/*.png
  • packages/web/public/bitbucket.svg is excluded by !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (21)
  • docs/docs.json (1 hunks)
  • docs/docs/connections/bitbucket-cloud.mdx (1 hunks)
  • docs/docs/connections/bitbucket-server.mdx (1 hunks)
  • docs/snippets/bitbucket-app-password.mdx (1 hunks)
  • docs/snippets/bitbucket-token.mdx (1 hunks)
  • package.json (1 hunks)
  • packages/backend/src/bitbucket.ts (1 hunks)
  • packages/backend/src/connectionManager.ts (2 hunks)
  • packages/backend/src/repoCompileUtils.ts (2 hunks)
  • packages/backend/src/repoManager.ts (5 hunks)
  • packages/schemas/src/v3/bitbucket.schema.ts (1 hunks)
  • packages/schemas/src/v3/bitbucket.type.ts (1 hunks)
  • packages/schemas/src/v3/connection.schema.ts (1 hunks)
  • packages/schemas/src/v3/connection.type.ts (2 hunks)
  • packages/schemas/src/v3/index.schema.ts (1 hunks)
  • packages/schemas/src/v3/index.type.ts (2 hunks)
  • packages/web/src/app/[domain]/search/components/codePreviewPanel/index.tsx (1 hunks)
  • packages/web/src/lib/utils.ts (5 hunks)
  • schemas/v3/bitbucket.json (1 hunks)
  • schemas/v3/connection.json (1 hunks)
  • vendor/zoekt (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
packages/schemas/src/v3/index.type.ts (2)
packages/schemas/src/v3/connection.type.ts (2)
  • BitbucketConnectionConfig (239-299)
  • GitRevisions (89-98)
packages/schemas/src/v3/bitbucket.type.ts (2)
  • BitbucketConnectionConfig (3-63)
  • GitRevisions (67-76)
packages/backend/src/connectionManager.ts (1)
packages/backend/src/repoCompileUtils.ts (1)
  • compileBitbucketConfig (320-427)
packages/schemas/src/v3/bitbucket.type.ts (2)
packages/schemas/src/v3/index.type.ts (2)
  • BitbucketConnectionConfig (305-365)
  • GitRevisions (155-164)
packages/schemas/src/v3/connection.type.ts (2)
  • BitbucketConnectionConfig (239-299)
  • GitRevisions (89-98)
packages/backend/src/repoManager.ts (3)
packages/schemas/src/v3/connection.type.ts (4)
  • GithubConnectionConfig (10-85)
  • GitlabConnectionConfig (99-165)
  • GiteaConnectionConfig (166-218)
  • BitbucketConnectionConfig (239-299)
packages/schemas/src/v3/bitbucket.type.ts (1)
  • BitbucketConnectionConfig (3-63)
packages/backend/src/utils.ts (1)
  • getTokenFromConfig (28-64)
packages/backend/src/repoCompileUtils.ts (4)
packages/schemas/src/v3/connection.type.ts (1)
  • BitbucketConnectionConfig (239-299)
packages/backend/src/bitbucket.ts (2)
  • getBitbucketReposFromConfig (52-102)
  • BitbucketRepository (22-22)
packages/backend/src/utils.ts (1)
  • marshalBool (20-22)
packages/backend/src/types.ts (1)
  • RepoMetadata (45-45)
🪛 LanguageTool
docs/docs/connections/bitbucket-server.mdx

[style] ~64-~64: Consider a shorter alternative to avoid wordiness.
Context: ...henticating with Bitbucket Data Center In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

docs/docs/connections/bitbucket-cloud.mdx

[style] ~72-~72: Consider a shorter alternative to avoid wordiness.
Context: ...## Authenticating with Bitbucket Cloud In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

🪛 Biome (1.9.4)
packages/backend/src/repoManager.ts

[error] 184-184: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 185-185: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 186-186: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 187-187: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

packages/schemas/src/v3/bitbucket.schema.ts

[error] 172-172: Do not add then to an object.

(lint/suspicious/noThenProperty)

packages/schemas/src/v3/index.schema.ts

[error] 692-692: Do not add then to an object.

(lint/suspicious/noThenProperty)

packages/schemas/src/v3/connection.schema.ts

[error] 613-613: Do not add then to an object.

(lint/suspicious/noThenProperty)

packages/backend/src/bitbucket.ts

[error] 316-316: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 503-503: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (24)
packages/web/src/app/[domain]/search/components/codePreviewPanel/index.tsx (1)

68-72: Great improvement to URL template handling!

This change properly handles the substitution of placeholders in URL query parameters, which is crucial for the Bitbucket integration. The code now correctly replaces template variables with their actual values in the query string portion of URLs.

vendor/zoekt (1)

1-1: Vendor submodule update approved

The zoekt subproject pointer has been bumped to commit 57019feee2a396ca79020150d50ebee8d55323c7. Since there are no functional changes in this directory beyond updating the vendored dependency, this looks correct. Please ensure the CI build and search integration tests pass against this new version.

package.json (1)

23-26: New dependency added correctly for Bitbucket support.

The addition of @coderabbitai/bitbucket as a dependency is appropriate for introducing Bitbucket support to the application. This dependency is used by the new Bitbucket integration functionality.

docs/docs.json (1)

34-35: Documentation navigation updated correctly for Bitbucket.

The new documentation pages for Bitbucket Cloud and Bitbucket Server have been properly added to the "Connecting your code" section, maintaining consistency with other connection types.

schemas/v3/connection.json (1)

16-19: Schema properly updated to include Bitbucket.

The connection schema has been correctly extended to include Bitbucket as a connection option in the oneOf array, following the same pattern as existing connection types.

packages/backend/src/connectionManager.ts (2)

7-7: Import statement updated to include compileBitbucketConfig.

The import statement has been correctly updated to include the new compileBitbucketConfig function from repoCompileUtils.js.


173-175: Bitbucket case added correctly to the connection type switch.

The new case for Bitbucket connection type has been properly implemented, following the same pattern as other connection types. The implementation correctly calls compileBitbucketConfig with the expected parameters.

packages/schemas/src/v3/index.type.ts (2)

11-12: Integration of Bitbucket to connection type union looks good

The addition of BitbucketConnectionConfig to the ConnectionConfig union type is implemented correctly, following the established pattern for other connection types.


305-365: BitbucketConnectionConfig interface properly defined

The BitbucketConnectionConfig interface is well-structured with appropriate fields for Bitbucket integration:

  • The type literal and authentication fields follow the same pattern as other connection types
  • Deployment type options ("cloud" | "server") are properly typed
  • Support for workspaces, projects, and repository filtering is included
  • Exclusion options match similar patterns in other connection configs
  • The revisions field correctly reuses the existing GitRevisions interface

The implementation maintains consistency with other connection types while addressing Bitbucket-specific requirements.

packages/schemas/src/v3/connection.type.ts (2)

7-8: Proper integration of BitbucketConnectionConfig in union type

The addition of BitbucketConnectionConfig to the ConnectionConfig union type is correctly implemented.


239-299: BitbucketConnectionConfig interface implementation is complete

The BitbucketConnectionConfig interface includes all necessary components for Bitbucket integration:

  • Authentication options (username and token)
  • Deployment type specification
  • Filtering capabilities for workspaces, projects, and repositories
  • Exclusion options for archived and forked repositories
  • Support for Git revision specifications

The interface maintains consistency with other connection types while accommodating Bitbucket-specific requirements.

packages/schemas/src/v3/bitbucket.type.ts (1)

1-77: Implementation looks good

The Bitbucket connection type and revisions interfaces are well-defined and properly documented. They match the schema implementation and align with the existing patterns in the codebase.

packages/schemas/src/v3/bitbucket.schema.ts (1)

165-176: JSON Schema conditional validation looks good

The conditional validation requiring the url property when deploymentType is "server" is correctly implemented. This ensures users provide the necessary URL for self-hosted Bitbucket deployments.

Note: The static analysis warning about "Do not add then to an object" can be ignored as then is a valid JSON Schema keyword for conditional validation.

🧰 Tools
🪛 Biome (1.9.4)

[error] 172-172: Do not add then to an object.

(lint/suspicious/noThenProperty)

packages/web/src/lib/utils.ts (5)

7-7: Good addition of Bitbucket logo import

The Bitbucket logo import is correctly added along with the other code host logos.


35-35: Properly extended CodeHostType

The CodeHostType type has been correctly extended to include "bitbucket" as an option.


114-125: Good implementation for Bitbucket code host info

The implementation correctly handles both "bitbucket-server" and "bitbucket-cloud" types, and maps them to the unified "bitbucket" type with appropriate display properties.


148-151: Correctly implemented icon handling

The Bitbucket icon is properly included in the getCodeHostIcon function.


162-162: Properly added authentication support

The function correctly includes "bitbucket" in the list of code hosts that support authentication.

schemas/v3/bitbucket.json (2)

10-13: LGTM: User authentication property defined properly.

The user property correctly specifies it's only needed when using app password authentication.


96-103: LGTM: Good conditional validation.

The schema correctly implements conditional validation to require the URL property when deployment type is "server".

packages/backend/src/repoCompileUtils.ts (2)

335-354: LGTM: Well-structured clone URL extraction.

The function properly handles clone URL extraction for both server and cloud deployments with good error handling.


405-414: LGTM: Proper metadata configuration.

The repository metadata is properly configured with the necessary information for the search index.

packages/schemas/src/v3/index.schema.ts (1)

685-696: LGTM: Proper conditional schema validation.

The schema correctly implements conditional validation to require the URL property when deployment type is "server". The static analysis warning about the "then" property is a false positive - this is valid JSON Schema syntax.

🧰 Tools
🪛 Biome (1.9.4)

[error] 692-692: Do not add then to an object.

(lint/suspicious/noThenProperty)

packages/schemas/src/v3/connection.schema.ts (1)

541-547: Minor: default deployment type is “cloud”; ensure doc examples match

The schema defaults deploymentType to "cloud", yet several documentation snippets still pass "deploymentType": "cloud". With the default in place, consider trimming the redundant field in examples to reduce clutter; otherwise leave as-is.

@msukkari msukkari requested a review from brendan-kellam April 25, 2025 00:06
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
docs/docs/connections/bitbucket-data-center.mdx (4)

6-7: Validate snippet imports and usage.

  • Ensure the import paths ('/snippets/...') resolve correctly in the MDX build; relative paths (e.g., ../../snippets/...`) might be required.
  • BitbucketAppPassword is imported but never used—either remove this import or include the corresponding <BitbucketAppPassword /> snippet.
- import BitbucketAppPassword from '/snippets/bitbucket-app-password.mdx';

38-57: Clean up the JSON code block for the exclusion example.

  • Insert a comma after "url" to maintain valid JSON.
  • Remove or relocate the //-style comments, as JSON does not support inline comments.
@@ -41,7 +41,7
-            "url": "https://mybitbucketdeployment.com"
+            "url": "https://mybitbucketdeployment.com",

65-66: Reduce wordiness in documentation text.

Simplify the sentence for clarity:

- In order to index private repositories, you'll need to provide an access token to Sourcebot.
+ To index private repositories, provide an access token to Sourcebot.

72-73: Enhance authentication examples.

Currently only <BitbucketToken /> is shown. Since app passwords are also supported, consider demonstrating <BitbucketAppPassword /> or clarifying the appropriate use cases for each method.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c6636d and 108d609.

📒 Files selected for processing (6)
  • docs/docs.json (1 hunks)
  • docs/docs/connections/bitbucket-data-center.mdx (1 hunks)
  • docs/docs/connections/overview.mdx (1 hunks)
  • docs/docs/overview.mdx (0 hunks)
  • docs/self-hosting/overview.mdx (1 hunks)
  • docs/snippets/connection-cards.mdx (0 hunks)
💤 Files with no reviewable changes (2)
  • docs/docs/overview.mdx
  • docs/snippets/connection-cards.mdx
✅ Files skipped from review due to trivial changes (2)
  • docs/self-hosting/overview.mdx
  • docs/docs/connections/overview.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/docs.json
🧰 Additional context used
🪛 LanguageTool
docs/docs/connections/bitbucket-data-center.mdx

[style] ~64-~64: Consider a shorter alternative to avoid wordiness.
Context: ...henticating with Bitbucket Data Center In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
docs/docs/connections/bitbucket-data-center.mdx (3)

1-4: Front matter is well-formed.

The YAML header correctly sets the page title and sidebar label, following the documentation conventions.


77-80: Approve schema reference section.

The link to schemas/v3/bitbucket.json within an accordion is correctly formatted and provides clear access to the schema.


81-178: Approve JSON schema content.

The embedded JSON schema accurately defines the Bitbucket connection configuration, with correct types, required fields, defaults, and constraints.

@brendan-kellam
Copy link
Contributor

Discussed offline: add support for web config

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/backend/src/bitbucket.ts (1)

358-377: 🛠️ Refactor suggestion

Fix authorization header when no credentials are provided.

The serverClient function currently includes an empty Authorization header when no credentials are provided, which might confuse the server. The header should be conditionally included only when authorizationString is not empty.

 const authorizationString = (() => {
     // If we're not given any credentials we return an empty auth string. This will only work if the project/repos are public
     if(!user && !token) {
-        return "";
+        return undefined;
     }

     // A user must be provided when using basic auth
     // https://developer.atlassian.com/server/bitbucket/rest/v906/intro/#authentication
     if (!user || user == "x-token-auth") {
         return `Bearer ${token}`;
     }
     return `Basic ${Buffer.from(`${user}:${token}`).toString('base64')}`;
 })();
 const clientOptions: ClientOptions = {
     baseUrl: url,
     headers: {
         Accept: "application/json",
-        Authorization: authorizationString,
+        ...(authorizationString ? { Authorization: authorizationString } : {}),
     },
 };
🧹 Nitpick comments (4)
docs/docs/connections/bitbucket-data-center.mdx (1)

65-65: Simplify wording for better readability.

Consider rephrasing "In order to index private repositories" to "To index private repositories" for conciseness.

-In order to index private repositories, you'll need to provide an access token to Sourcebot.
+To index private repositories, you'll need to provide an access token to Sourcebot.
docs/docs/connections/bitbucket-cloud.mdx (1)

73-73: Simplify wording for better readability.

Consider rephrasing "In order to index private repositories" to "To index private repositories" for conciseness.

-In order to index private repositories, you'll need to provide authentication credentials. You can do this using an `App Password` or an `Access Token`
+To index private repositories, you'll need to provide authentication credentials. You can do this using an `App Password` or an `Access Token`
packages/backend/src/repoManager.ts (1)

180-191: Simplify the switch statement by removing redundant cases.

The switch statement has several cases that all result in the same empty string, making them redundant. Only the 'gitlab' case produces a different result.

 let username = (() => {
     switch (repo.external_codeHostType) {
         case 'gitlab':
             return 'oauth2';
-        case 'bitbucket-server':
-        case 'bitbucket-cloud':
-        case 'github':
-        case 'gitea':
         default:
             return '';
     }
 })();
🧰 Tools
🪛 Biome (1.9.4)

[error] 184-184: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 185-185: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 186-186: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 187-187: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

packages/backend/src/bitbucket.ts (1)

338-338: Improve code quality with optional chaining and simplified Boolean expressions.

The static analysis detected redundant double-negation and missing optional chaining, which can be improved for better readability and maintainability.

-        if (config.exclude?.repos && config.exclude.repos.includes(cloudRepo.full_name!)) {
+        if (config.exclude?.repos?.includes(cloudRepo.full_name!)) {
             return true;
         }

-        if (!!config.exclude?.archived) {
+        if (config.exclude?.archived) {
             logger.warn(`Exclude archived repos flag provided in config but Bitbucket Cloud does not support archived repos. Ignoring...`);
         }

...

-        if (config.exclude?.repos && config.exclude.repos.includes(`${projectName}/${repoSlug}`)) {
+        if (config.exclude?.repos?.includes(`${projectName}/${repoSlug}`)) {
             return true;
         }

Also applies to: 342-342, 536-536

🧰 Tools
🪛 Biome (1.9.4)

[error] 338-338: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 108d609 and 53248d8.

📒 Files selected for processing (5)
  • docs/docs/connections/bitbucket-cloud.mdx (1 hunks)
  • docs/docs/connections/bitbucket-data-center.mdx (1 hunks)
  • packages/backend/src/bitbucket.ts (1 hunks)
  • packages/backend/src/repoCompileUtils.ts (2 hunks)
  • packages/backend/src/repoManager.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/backend/src/repoCompileUtils.ts
🧰 Additional context used
🪛 LanguageTool
docs/docs/connections/bitbucket-cloud.mdx

[style] ~72-~72: Consider a shorter alternative to avoid wordiness.
Context: ...## Authenticating with Bitbucket Cloud In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

docs/docs/connections/bitbucket-data-center.mdx

[style] ~64-~64: Consider a shorter alternative to avoid wordiness.
Context: ...henticating with Bitbucket Data Center In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

🪛 Biome (1.9.4)
packages/backend/src/bitbucket.ts

[error] 338-338: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 342-342: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 536-536: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/backend/src/repoManager.ts

[error] 184-184: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 185-185: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 186-186: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 187-187: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (4)
packages/backend/src/bitbucket.ts (4)

242-255: Good query parameter handling for project filtering.

The implementation correctly uses the params.query option to pass the project filter query parameter, which prevents potential issues with special characters in project names.


74-82: ⚠️ Potential issue

Missing property in notFound object structure.

The notFound object is missing a projects property, which is needed to correctly track not-found projects. In the current implementation, projects are incorrectly tracked in the orgs array (see line 93).

Add a projects property to the notFound object:

 let notFound: {
     orgs: string[],
     users: string[],
     repos: string[],
+    projects: string[],
 } = {
     orgs: [],
     users: [],
     repos: [],
+    projects: [],
 };

93-93: ⚠️ Potential issue

Projects are being incorrectly tracked in orgs array.

Failed project fetches are being stored in notFound.orgs instead of a dedicated projects array, which is misleading and will cause confusion in error reporting.

-    notFound.orgs = notFoundProjects;
+    notFound.projects = notFoundProjects;

357-377: 🛠️ Refactor suggestion

Fix inconsistent authorization handling in server client.

The server client authorization logic is inconsistent with the cloud client implementation. It always includes the Authorization header, even when it's an empty string, which may cause issues with request validation.

 const authorizationString = (() => {
     // If we're not given any credentials we return an empty auth string. This will only work if the project/repos are public
     if(!user && !token) {
-        return "";
+        return undefined;
     }

     // A user must be provided when using basic auth
     // https://developer.atlassian.com/server/bitbucket/rest/v906/intro/#authentication
     if (!user || user == "x-token-auth") {
         return `Bearer ${token}`;
     }
     return `Basic ${Buffer.from(`${user}:${token}`).toString('base64')}`;
 })();
 const clientOptions: ClientOptions = {
     baseUrl: url,
     headers: {
         Accept: "application/json",
-        Authorization: authorizationString,
+        ...(authorizationString ? { Authorization: authorizationString } : {}),
     },
 };
🧹 Nitpick comments (3)
packages/backend/src/bitbucket.ts (3)

336-348: Improve code with optional chaining and avoid double negation.

The code can be improved by using optional chaining and avoiding redundant double negation as highlighted by static analysis.

-    if (config.exclude?.repos && config.exclude.repos.includes(cloudRepo.full_name!)) {
+    if (config.exclude?.repos?.includes(cloudRepo.full_name!)) {
         return true;
     }

-    if (!!config.exclude?.archived) {
+    if (config.exclude?.archived) {
         logger.warn(`Exclude archived repos flag provided in config but Bitbucket Cloud does not support archived repos. Ignoring...`);
     }

-    if (!!config.exclude?.forks && cloudRepo.parent !== undefined) {
+    if (config.exclude?.forks && cloudRepo.parent !== undefined) {
         return true;
     }
🧰 Tools
🪛 Biome (1.9.4)

[error] 337-337: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 341-341: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


402-416: Server pagination implementation may not handle nextPageStart correctly.

The Bitbucket Server pagination implementation correctly checks for isLastPage, but it needs to ensure that nextPageStart is properly handled when it's undefined.

 while (true) {
     const response = await get(path, nextStart);

     if (!response.values || response.values.length === 0) { 
         break;
     }

     results.push(...response.values);

     if (response.isLastPage) {
         break;
     }

     nextStart = response.nextPageStart;
+    if (nextStart === undefined) {
+        break;
+    }
 }

534-546: Improve code with optional chaining.

Similar to the cloud implementation, use optional chaining for cleaner code.

-    if (config.exclude?.repos && config.exclude.repos.includes(`${projectName}/${repoSlug}`)) {
+    if (config.exclude?.repos?.includes(`${projectName}/${repoSlug}`)) {
         return true;
     }

-    if (!!config.exclude?.archived && serverRepo.archived) {
+    if (config.exclude?.archived && serverRepo.archived) {
         return true;
     }

-    if (!!config.exclude?.forks && serverRepo.origin !== undefined) {
+    if (config.exclude?.forks && serverRepo.origin !== undefined) {
         return true;
     }
🧰 Tools
🪛 Biome (1.9.4)

[error] 535-535: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53248d8 and 82c122c.

📒 Files selected for processing (3)
  • Makefile (1 hunks)
  • packages/backend/src/bitbucket.ts (1 hunks)
  • packages/web/src/actions.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/backend/src/bitbucket.ts (5)
packages/backend/src/logger.ts (1)
  • createLogger (46-46)
packages/schemas/src/v3/bitbucket.type.ts (1)
  • BitbucketConnectionConfig (3-63)
packages/backend/src/utils.ts (2)
  • getTokenFromConfig (28-64)
  • fetchWithRetry (105-132)
packages/web/src/lib/serviceError.ts (1)
  • notFound (91-97)
packages/web/src/lib/utils.ts (1)
  • measure (235-251)
🪛 Biome (1.9.4)
packages/backend/src/bitbucket.ts

[error] 337-337: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 341-341: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 535-535: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (8)
Makefile (1)

36-36: Addition of Prisma migration reset is a good complement to the soft-reset process.

The addition of yarn dev:prisma:migrate:reset to the soft-reset target ensures that database schema changes related to the Bitbucket integration will be properly reset during development. This complements the existing cleanup steps (removing the .sourcebot directory and flushing Redis data).

packages/web/src/actions.ts (1)

531-532: Bitbucket case handling added appropriately.

The code now treats Bitbucket connections similarly to GitHub connections when extracting repository counts and token presence. This is a necessary update to support the new Bitbucket integration.

packages/backend/src/bitbucket.ts (6)

1-22: Well-structured imports and type definitions.

The imports and constant definitions are well-organized, properly separating Bitbucket Cloud and Server API interfaces. The exported BitbucketRepository type provides a clean abstraction over both Cloud and Server repository types.


24-34: Good interface design for BitbucketClient.

The BitbucketClient interface provides a clean abstraction that works for both Bitbucket Cloud and Server implementations. This design pattern allows for consistent interaction with different Bitbucket deployments while handling their specific implementation details internally.


114-126: Good authorization handling for cloud client.

The authorization handling correctly handles different authentication methods (Bearer token vs Basic auth) and properly omits the Authorization header when no token is provided.


159-170: Pagination logic for cloud implementation looks correct.

The pagination handling for Bitbucket Cloud correctly checks for the existence of response.next to determine when to stop fetching more pages.


60-110: Well-structured main function with clear error handling.

The getBitbucketReposFromConfig function is well-structured with proper error handling for missing server URLs and appropriate client selection based on deployment type. The repository filtering and aggregation logic is clean and follows the same pattern for different repository sources.


175-226: Comprehensive error handling in cloud repository fetching.

The error handling in cloudGetReposForWorkspace is comprehensive, using Promise.allSettled to gracefully handle errors for individual workspaces and distinguishing between not-found errors (404) and other errors. The Sentry exception capture and logging are also appropriate.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
docs/docs/connections/bitbucket-cloud.mdx (1)

35-44: LGTM! The project examples are now correct.

The example correctly demonstrates using project identifiers rather than repository paths in the projects array.

🧹 Nitpick comments (4)
packages/web/src/app/[domain]/connections/new/[type]/page.tsx (1)

49-49: Remove extra whitespace

There are extra spaces on this line that don't match the formatting of other similar blocks.

-    
+
packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx (1)

130-145: LGTM: Added Bitbucket selection buttons

The code host selection UI has been updated with properly configured buttons for both Bitbucket variants, including appropriate event tracking.

Consider name consistency

Note that "Bitbucket DC" is used in the UI (line 140) while "Bitbucket Data Center" is used elsewhere. This might be intentional for UI space constraints, but worth confirming for consistency.

docs/docs/connections/bitbucket-cloud.mdx (1)

73-73: Consider simplifying the phrasing for better conciseness.

The phrase "In order to index" could be simplified.

-In order to index private repositories, you'll need to provide authentication credentials. You can do this using an `App Password` or an `Access Token`
+To index private repositories, you'll need to provide authentication credentials. You can do this using an `App Password` or an `Access Token`
packages/web/src/app/[domain]/connections/quickActions.tsx (1)

564-564: Consider removing redundant comments.

The code contains standalone comments (// exclude archived and // exclude forked) that are redundant with the action names. These could be removed for consistency with other quick actions in the file.

Also applies to: 574-574

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82c122c and 44ce5bc.

📒 Files selected for processing (12)
  • docs/docs/connections/bitbucket-cloud.mdx (1 hunks)
  • packages/web/src/actions.ts (3 hunks)
  • packages/web/src/app/[domain]/components/codeHostIconButton.tsx (2 hunks)
  • packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx (1 hunks)
  • packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx (1 hunks)
  • packages/web/src/app/[domain]/components/connectionCreationForms/index.ts (1 hunks)
  • packages/web/src/app/[domain]/connections/components/newConnectionCard.tsx (1 hunks)
  • packages/web/src/app/[domain]/connections/new/[type]/page.tsx (2 hunks)
  • packages/web/src/app/[domain]/connections/quickActions.tsx (5 hunks)
  • packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx (4 hunks)
  • packages/web/src/lib/posthogEvents.ts (1 hunks)
  • packages/web/src/lib/utils.ts (5 hunks)
✅ Files skipped from review due to trivial changes (3)
  • packages/web/src/app/[domain]/components/connectionCreationForms/index.ts
  • packages/web/src/app/[domain]/components/codeHostIconButton.tsx
  • packages/web/src/app/[domain]/connections/components/newConnectionCard.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/web/src/actions.ts
  • packages/web/src/lib/utils.ts
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/web/src/app/[domain]/connections/new/[type]/page.tsx (3)
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx (1)
  • BitbucketCloudConnectionCreationForm (30-49)
packages/web/src/app/[domain]/components/connectionCreationForms/index.ts (2)
  • BitbucketCloudConnectionCreationForm (5-5)
  • BitbucketDataCenterConnectionCreationForm (6-6)
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx (1)
  • BitbucketDataCenterConnectionCreationForm (29-48)
packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx (5)
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx (1)
  • BitbucketCloudConnectionCreationForm (30-49)
packages/web/src/app/[domain]/components/connectionCreationForms/index.ts (2)
  • BitbucketCloudConnectionCreationForm (5-5)
  • BitbucketDataCenterConnectionCreationForm (6-6)
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx (1)
  • BitbucketDataCenterConnectionCreationForm (29-48)
packages/web/src/app/[domain]/components/codeHostIconButton.tsx (1)
  • CodeHostIconButton (14-35)
packages/web/src/lib/utils.ts (1)
  • getCodeHostIcon (129-157)
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx (1)
packages/web/src/app/[domain]/connections/quickActions.tsx (1)
  • bitbucketDataCenterQuickActions (488-585)
packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx (2)
packages/web/src/app/[domain]/components/connectionCreationForms/index.ts (1)
  • BitbucketCloudConnectionCreationForm (5-5)
packages/web/src/app/[domain]/connections/quickActions.tsx (1)
  • bitbucketCloudQuickActions (395-486)
🪛 LanguageTool
docs/docs/connections/bitbucket-cloud.mdx

[style] ~72-~72: Consider a shorter alternative to avoid wordiness.
Context: ...## Authenticating with Bitbucket Cloud In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

🪛 Biome (1.9.4)
packages/web/src/lib/posthogEvents.ts

[error] 241-241: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 242-242: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (14)
packages/web/src/lib/posthogEvents.ts (1)

241-242: LGTM: Added event tracking for Bitbucket code hosts

The new event types for Bitbucket Cloud and Bitbucket Data Center selection follow the same pattern as other onboarding code host selections.

🧰 Tools
🪛 Biome (1.9.4)

[error] 241-241: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 242-242: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

packages/web/src/app/[domain]/connections/new/[type]/page.tsx (2)

8-10: LGTM: Added Bitbucket form imports

The imports for the new Bitbucket connection creation forms have been correctly added.


42-48: LGTM: Added Bitbucket connection type handling

The new conditional blocks for Bitbucket Cloud and Bitbucket Data Center connection types follow the same pattern as the existing ones, correctly rendering the appropriate form component with the onCreated callback.

packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx (2)

12-28: LGTM: Well-implemented validation logic

The validation function properly checks that at least one project, repository, or workspace is specified and that they contain non-empty strings.


30-49: LGTM: Properly structured Bitbucket Cloud connection form

The BitbucketCloudConnectionCreationForm follows the established pattern for connection creation forms, using the shared form component with Bitbucket Cloud specific configuration, schema, and quick actions.

packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx (3)

10-12: LGTM: Added Bitbucket form imports

The imports for the new Bitbucket connection creation forms have been correctly added.


84-100: LGTM: Added Bitbucket connection handling

The conditional rendering for Bitbucket Cloud and Bitbucket Data Center connection forms follows the established pattern, with proper back button and form component.


113-113: LGTM: Improved grid layout

The grid layout has been explicitly defined as responsive (1 column on mobile, 2 columns on small screens) with improved spacing and max width constraints.

packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx (1)

1-48: LGTM! Clean Bitbucket Data Center form implementation.

The component is well-structured and properly uses the shared connection creation form pattern. The validation logic ensures at least one project or repository is specified, which is a good UX safeguard.

docs/docs/connections/bitbucket-cloud.mdx (1)

1-201: LGTM! Comprehensive documentation for Bitbucket Cloud integration.

The documentation provides clear examples for different syncing scenarios, authentication methods, and includes the complete schema reference. The use of Accordion and Tabs components helps organize the content effectively.

🧰 Tools
🪛 LanguageTool

[style] ~72-~72: Consider a shorter alternative to avoid wordiness.
Context: ...## Authenticating with Bitbucket Cloud In order to index private repositories, you'll need...

(IN_ORDER_TO_PREMIUM)

packages/web/src/app/[domain]/connections/quickActions.tsx (4)

3-5: LGTM! Proper import for Bitbucket and corrected Gitea imports.

The import for BitbucketConnectionConfig is correctly added, and the import for GiteaConnectionConfig is properly updated to use the specific type file.


104-104: LGTM! Name standardization improves clarity.

Updating the quick action names to follow a consistent pattern of "Set url to [Service] instance" improves clarity and consistency across different code hosts.

Also applies to: 294-294, 364-364


395-486: LGTM! Comprehensive set of Bitbucket Cloud quick actions.

The quick actions for Bitbucket Cloud cover all the essential configuration options including username, workspaces, repositories, projects, and exclusion rules.


488-585: LGTM! Comprehensive set of Bitbucket Data Center quick actions.

The quick actions provide appropriate defaults and examples specific to the Bitbucket Data Center environment, including setting the server URL and managing projects and repositories.

brendan-kellam
brendan-kellam previously approved these changes Apr 25, 2025
@brendan-kellam
Copy link
Contributor

nit: could you add a changelog entry?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
packages/backend/src/repoCompileUtils.ts (1)

386-387: Fix for fork and archive status detection looks good.

You've properly implemented the detection of fork and archive status for both Bitbucket Cloud and Server repositories, as was suggested in a previous review.

packages/backend/src/repoManager.ts (1)

193-217: Good fix for empty credentials in clone URL.

The implementation now properly returns undefined when no credentials are found, avoiding URLs with empty authentication like https://:@host/repo.git. This addresses the issue raised in the previous review comment.

🧹 Nitpick comments (4)
packages/web/src/lib/posthogEvents.ts (1)

241-242: Consider defining explicit type shapes across the codebase

The static analysis tool flagged the use of empty object types ({}), which represent "any non-nullable value" rather than "no properties". While this pattern is used consistently throughout the file (and there's an eslint disable comment at the top), consider eventually refactoring these to either a dedicated empty interface or a more explicit representation in a future cleanup task.

🧰 Tools
🪛 Biome (1.9.4)

[error] 241-241: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 242-242: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

packages/backend/src/repoManager.ts (1)

180-192: Simplify username initialization logic.

The switch statement contains several "useless case clauses" that all fall through to the default case, making the code unnecessarily verbose.

-        let username = (() => {
-            switch (repo.external_codeHostType) {
-                case 'gitlab':
-                    return 'oauth2';
-                case 'bitbucket-cloud':
-                case 'bitbucket-server':
-                case 'github':
-                case 'gitea':
-                default:
-                    return '';
-            }
-        })();
+        let username = repo.external_codeHostType === 'gitlab' ? 'oauth2' : '';
🧰 Tools
🪛 Biome (1.9.4)

[error] 184-184: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 185-185: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 186-186: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 187-187: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

packages/web/src/app/[domain]/components/importSecretDialog.tsx (2)

269-289: Consider adding screenshot guidance for Bitbucket token creation

Unlike the GitHub, GitLab, and Gitea components, the Bitbucket components don't include screenshots to guide users through the token creation process. While linking to documentation is helpful, screenshots provide immediate visual guidance that can improve the user experience.

Consider adding screenshots similar to the other code hosts:

const BitbucketCloudPATCreationStep = ({ step }: { step: number }) => {
    return (
        <SecretCreationStep
            step={step}
            title="Create an Access Token"
            description=<span>Please check out our <Link href="https://docs.sourcebot.dev/docs/connections/bitbucket-cloud#authenticating-with-bitbucket-cloud" target="_blank" className="underline">docs</Link> for more information on how to create auth credentials for Bitbucket Cloud.</span>
        >
+           <Image
+               className="mx-auto rounded-sm"
+               src={bitbucketCloudPatCreation}
+               alt="Create a Bitbucket Cloud access token"
+               width={500}
+               height={500}
+           />
        </SecretCreationStep>
    )
}

Note: This would require importing the corresponding image at the top of the file:

import bitbucketCloudPatCreation from "@/public/bitbucket_cloud_pat_creation.png";
import bitbucketServerPatCreation from "@/public/bitbucket_server_pat_creation.png";

85-100: Consider adding changelog entry for Bitbucket support

As mentioned in the PR comments by brendan-kellam, please remember to add a changelog entry for the new Bitbucket support feature.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44ce5bc and aea39c6.

📒 Files selected for processing (13)
  • packages/backend/src/repoCompileUtils.ts (2 hunks)
  • packages/backend/src/repoManager.ts (5 hunks)
  • packages/web/src/actions.ts (7 hunks)
  • packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx (1 hunks)
  • packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx (1 hunks)
  • packages/web/src/app/[domain]/components/importSecretDialog.tsx (3 hunks)
  • packages/web/src/app/[domain]/connections/[id]/components/configSetting.tsx (3 hunks)
  • packages/web/src/app/[domain]/connections/[id]/page.tsx (1 hunks)
  • packages/web/src/app/[domain]/connections/components/newConnectionCard.tsx (1 hunks)
  • packages/web/src/app/[domain]/connections/new/[type]/page.tsx (2 hunks)
  • packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx (4 hunks)
  • packages/web/src/lib/posthogEvents.ts (1 hunks)
  • packages/web/src/lib/utils.ts (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/web/src/app/[domain]/connections/[id]/page.tsx
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/web/src/app/[domain]/connections/components/newConnectionCard.tsx
  • packages/web/src/app/[domain]/connections/new/[type]/page.tsx
  • packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx
  • packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx
  • packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx
  • packages/web/src/lib/utils.ts
  • packages/web/src/actions.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/web/src/app/[domain]/connections/[id]/components/configSetting.tsx (2)
packages/web/src/lib/utils.ts (1)
  • CodeHostType (35-35)
packages/web/src/app/[domain]/connections/quickActions.tsx (2)
  • bitbucketCloudQuickActions (395-486)
  • bitbucketDataCenterQuickActions (488-585)
🪛 Biome (1.9.4)
packages/backend/src/repoManager.ts

[error] 184-184: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 185-185: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 186-186: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


[error] 187-187: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

packages/web/src/lib/posthogEvents.ts

[error] 241-241: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 242-242: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (14)
packages/web/src/lib/posthogEvents.ts (1)

241-242: LGTM: Appropriate event types added for Bitbucket support

The two new event types follow the established naming pattern for onboarding selection events and correctly address both Bitbucket Cloud and Bitbucket Server (Data Center) variants as specified in the PR objectives.

🧰 Tools
🪛 Biome (1.9.4)

[error] 241-241: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 242-242: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

packages/web/src/app/[domain]/connections/[id]/components/configSetting.tsx (3)

16-16: Properly imports Bitbucket-related dependencies.

The imports include necessary Bitbucket schemas, types, and quick actions needed for the new Bitbucket integration.

Also applies to: 30-31


36-36: Good type safety improvement.

Refining the prop type from string to CodeHostType union improves type safety and makes the component's API more explicit.


61-77: Clean implementation of Bitbucket connection types.

The implementation for both Bitbucket Cloud and Bitbucket Server follows the established pattern of the codebase, making the code consistent and maintainable.

packages/backend/src/repoCompileUtils.ts (2)

6-8: Well-structured imports for Bitbucket integration.

The imports appropriately separate the generic Bitbucket repository type from the specific Cloud and Server implementations, allowing for type-safe operations later in the code.


320-434: Thorough implementation of Bitbucket repository compilation.

The function correctly handles the differences between Bitbucket Cloud and Server deployments, with proper error handling and type safety. The implementation mirrors patterns used for other code hosts while addressing Bitbucket-specific concerns.

I appreciate how the implementation:

  1. Distinguishes between Bitbucket Cloud and Server deployments
  2. Properly extracts clone URLs and web URLs with detailed error messages
  3. Correctly sets metadata fields including repository visibility, fork status, and archive status
packages/backend/src/repoManager.ts (5)

173-178: Good method rename and return type change.

Renaming from getTokenForRepo to getAuthForRepo better reflects the method's purpose, and changing the return type to include both username and password improves the API clarity.


204-208: Good handling of Bitbucket-specific authentication.

The code correctly handles Bitbucket authentication by setting the appropriate username, which is required for Bitbucket repository cloning.


247-252: Clean implementation of auth object usage.

The code now uses the auth object directly to set both username and password on the clone URL, removing previous special-case logic and making the code more maintainable.


331-337: Improved error logging with repository details.

Adding the repository name to error logs provides more context and makes debugging easier, especially when dealing with many repositories.


466-466: Enhanced logging for garbage collection.

Including the repository display name in the log message provides better context for monitoring and debugging.

packages/web/src/app/[domain]/components/importSecretDialog.tsx (3)

91-94: Good implementation of Bitbucket support in host type selection

The switch statement correctly handles the two new Bitbucket code host types by rendering their respective PAT creation step components. This is consistent with the approach used for other code hosts.


295-295: Appropriate change to make children prop optional

Making the children prop optional is necessary to support the Bitbucket components that don't include image children. This change is correct and maintains compatibility with existing components.


186-186: Good generalization of placeholder text

Changing the placeholder from "my-github-token" to "my-access-token" is appropriate as the dialog now supports multiple code hosts beyond GitHub. This small change improves consistency in the UI.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/schemas/src/v3/index.schema.ts (1)

637-748: Solid schema addition for Bitbucket support

The schema for Bitbucket connection configuration looks well-structured with good support for both Bitbucket Cloud and Bitbucket Data Center (Server) deployments.

I do see a few opportunities for enhancement:

  1. The projects and repos properties have minimal descriptions. Consider adding more details about expected format (e.g., whether they need workspace/project prefixes).

  2. Consider adding pattern validations for items in the workspaces, projects, and repos arrays, similar to other connection types.

  "workspaces": {
    "type": "array",
    "items": {
-     "type": "string"
+     "type": "string",
+     "pattern": "^[\\w.-]+$"
    },
    "description": "List of workspaces to sync. Ignored if deploymentType is server."
  },
  1. The workspaces property comment states it's ignored for server deployments, but there's no validation to enforce this. Consider adding a conditional schema validation using if/then to prevent confusion.
🧰 Tools
🪛 Biome (1.9.4)

[error] 742-742: Do not add then to an object.

(lint/suspicious/noThenProperty)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aea39c6 and 1e01446.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • docs/docs.json (1 hunks)
  • package.json (1 hunks)
  • packages/schemas/src/v3/index.schema.ts (1 hunks)
  • packages/schemas/src/v3/index.type.ts (2 hunks)
  • packages/web/src/actions.ts (8 hunks)
  • packages/web/src/app/[domain]/components/connectionCreationForms/index.ts (1 hunks)
  • packages/web/src/app/[domain]/connections/[id]/page.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • CHANGELOG.md
  • packages/web/src/app/[domain]/components/connectionCreationForms/index.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • package.json
  • docs/docs.json
  • packages/web/src/app/[domain]/connections/[id]/page.tsx
  • packages/web/src/actions.ts
  • packages/schemas/src/v3/index.type.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/schemas/src/v3/index.schema.ts

[error] 742-742: Do not add then to an object.

(lint/suspicious/noThenProperty)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
packages/schemas/src/v3/index.schema.ts (1)

742-742: Ignore the static analysis warning about then property

The static analysis tool flagged this line, but it's a false positive. The then keyword is a valid part of JSON Schema conditional validation and is being used correctly here to enforce the requirement for a URL when using Bitbucket Server.

🧰 Tools
🪛 Biome (1.9.4)

[error] 742-742: Do not add then to an object.

(lint/suspicious/noThenProperty)

@msukkari msukkari merged commit b6dedc7 into main Apr 25, 2025
5 checks passed
@msukkari msukkari mentioned this pull request Apr 25, 2025
@msukkari
Copy link
Contributor Author

#14

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