Skip to content

feat(search_contexts): Add ability to include/exclude connections in search contexts #399

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 2 commits into from
Jul 27, 2025

Conversation

msukkari
Copy link
Contributor

@msukkari msukkari commented Jul 27, 2025

    "contexts": {
        "sourcebot": {
            "include": [
                "github.com/sourcebot-dev/sourcebot"
            ]
        },
        "nextjs": {
            "includeConnections": [
                "nextjs"
            ],
            "excludeConnections": [
                "sourcebot"
            ]
        }
    }

Summary by CodeRabbit

  • New Features

    • Added support for including or excluding connections in the search context, allowing more flexible control over which repositories are included or excluded during searches.
  • Documentation

    • Updated documentation and schema references to reflect the new includeConnections and excludeConnections options and the optional nature of the include property in search contexts.

@msukkari msukkari requested a review from brendan-kellam July 27, 2025 01:41
Copy link

coderabbitai bot commented Jul 27, 2025

Walkthrough

Support for including and excluding repository connections in search contexts was added across schema definitions, TypeScript types, and documentation. The include property for repositories was made optional. Logic in the synchronization process was updated to handle these new connection-based inclusion and exclusion lists, affecting how repositories are resolved for each search context.

Changes

File(s) Change Summary
CHANGELOG.md Updated to document the new include/exclude connections feature for search contexts.
docs/snippets/schemas/v3/index.schema.mdx
docs/snippets/schemas/v3/searchContext.schema.mdx
schemas/v3/searchContext.json
Added optional includeConnections and excludeConnections arrays to the SearchContext schema; made include optional.
packages/schemas/src/v3/index.schema.ts
packages/schemas/src/v3/searchContext.schema.ts
Updated schema definitions to add optional connection-based inclusion/exclusion; include is now optional.
packages/schemas/src/v3/index.type.ts
packages/schemas/src/v3/searchContext.type.ts
Modified SearchContext interface: include is now optional; added includeConnections and excludeConnections.
packages/shared/src/ee/syncSearchContexts.ts Enhanced logic to resolve repositories using both direct and connection-based inclusion/exclusion lists.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SyncJob
    participant DB
    participant ConnectionService

    User->>SyncJob: Define search context (include, exclude, includeConnections, excludeConnections)
    SyncJob->>DB: Fetch all repositories
    alt include pattern specified
        SyncJob->>DB: Filter repos by include pattern
    end
    alt includeConnections specified
        SyncJob->>ConnectionService: Fetch connections by name/org
        ConnectionService-->>SyncJob: Return associated repositories
        SyncJob->>DB: Add these repos to inclusion list
    end
    alt exclude pattern specified
        SyncJob->>DB: Remove repos by exclude pattern
    end
    alt excludeConnections specified
        SyncJob->>ConnectionService: Fetch connections by name/org
        ConnectionService-->>SyncJob: Return associated repositories
        SyncJob->>DB: Remove these repos from inclusion list
    end
    SyncJob->>DB: Upsert search context with resolved repos
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

In the meadow of code where schemas grow,
Connections now join the search context show.
Include or exclude, the logic expands,
Bringing more power to curious hands.
With optional fields and lists anew,
The search context hops—more clever, more true!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch msukkarieh/connection_context

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate unit tests to generate unit tests for 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.

This comment has been minimized.

@msukkari msukkari changed the title Add ability to include/exclude connections in search contexts feat(search_contexts): Add ability to include/exclude connections in search contexts Jul 27, 2025
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/snippets/schemas/v3/index.schema.mdx (1)

245-251: Same duplication concern for excludeConnections

See the previous comment – the same reasoning applies here.

🧹 Nitpick comments (4)
packages/shared/src/ee/syncSearchContexts.ts (1)

46-71: Consider deduplicating repositories to avoid potential issues.

The logic correctly fetches repositories from included connections, but concatenating without deduplication could result in duplicate entries if the same repository belongs to multiple connections or was already included via patterns.

Consider deduplicating the repository list:

                for (const connection of connections) {
-                   newReposInContext = newReposInContext.concat(connection.repos.map(repo => repo.repo));
+                   const connectionRepos = connection.repos.map(repo => repo.repo);
+                   for (const repo of connectionRepos) {
+                       if (!newReposInContext.find(existing => existing.id === repo.id)) {
+                           newReposInContext.push(repo);
+                       }
+                   }
                }

Or use a more efficient approach with a Set:

+               const existingIds = new Set(newReposInContext.map(repo => repo.id));
                for (const connection of connections) {
-                   newReposInContext = newReposInContext.concat(connection.repos.map(repo => repo.repo));
+                   const connectionRepos = connection.repos.map(repo => repo.repo);
+                   newReposInContext.push(...connectionRepos.filter(repo => !existingIds.has(repo.id)));
+                   connectionRepos.forEach(repo => existingIds.add(repo.id));
                }
docs/snippets/schemas/v3/index.schema.mdx (3)

95-101: Strengthen validation for includeConnections array items

The items are currently validated as generic strings.
Everywhere else, connection identifiers are constrained by the regex ^[a-zA-Z0-9_-]+$. Adding the same pattern here (and optionally a minItems: 1 plus an example) will prevent typos and empty arrays from silently passing validation.

 "includeConnections": {
   "type": "array",
   "description": "List of connections to include in the search context.",
-  "items": {
-    "type": "string"
-  }
+  "items": {
+    "type": "string",
+    "pattern": "^[a-zA-Z0-9_-]+$"
+  },
+  "minItems": 1,
+  "examples": [["github-enterprise", "gitlab-prod"]]
 }

115-121: Mirror the tighter validation in excludeConnections

For symmetry with the previous suggestion, apply the same pattern, minItems, and examples attributes here.


225-231: Duplication between definitions – consider a $ref

includeConnections is now declared twice (root SearchContext and the per-context patternProperties). Keeping two in-place copies invites drift in future edits.
Using a $ref to a single SearchContext definition (or generating the file via $defs in the code-gen step) would eliminate this risk.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e50469 and 7dea6e4.

📒 Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • docs/snippets/schemas/v3/index.schema.mdx (4 hunks)
  • docs/snippets/schemas/v3/searchContext.schema.mdx (2 hunks)
  • packages/schemas/src/v3/index.schema.ts (4 hunks)
  • packages/schemas/src/v3/index.type.ts (1 hunks)
  • packages/schemas/src/v3/searchContext.schema.ts (2 hunks)
  • packages/schemas/src/v3/searchContext.type.ts (1 hunks)
  • packages/shared/src/ee/syncSearchContexts.ts (2 hunks)
  • schemas/v3/searchContext.json (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*

📄 CodeRabbit Inference Engine (.cursor/rules/style.mdc)

Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

Files:

  • CHANGELOG.md
  • packages/schemas/src/v3/index.type.ts
  • packages/schemas/src/v3/searchContext.type.ts
  • packages/shared/src/ee/syncSearchContexts.ts
  • packages/schemas/src/v3/index.schema.ts
  • packages/schemas/src/v3/searchContext.schema.ts
  • docs/snippets/schemas/v3/index.schema.mdx
  • schemas/v3/searchContext.json
  • docs/snippets/schemas/v3/searchContext.schema.mdx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (14)
CHANGELOG.md (1)

12-12: LGTM! Changelog entry properly documents the new feature.

The entry accurately describes the functionality and follows the standard changelog format with appropriate PR reference.

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

117-129: LGTM! Interface changes correctly implement the new connection filtering feature.

The changes properly:

  • Make the include property optional for more flexible configurations
  • Add well-documented optional properties for connection inclusion and exclusion
  • Maintain type safety with appropriate string array types
schemas/v3/searchContext.json (1)

20-26: LGTM! Schema additions are well-structured and consistent.

The new properties are properly defined with:

  • Correct array type definitions for string values
  • Clear and descriptive documentation
  • Consistent structure with existing properties

Also applies to: 40-46

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

21-27: LGTM! Schema definitions are consistent and well-structured.

The new connection properties follow the established schema patterns with proper type definitions and descriptive documentation.

Also applies to: 41-47

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

10-14: LGTM! Interface changes maintain consistency across schema files.

The SearchContext interface correctly implements the new optional properties with proper typing and documentation that matches the main schema definitions.

Also applies to: 19-22

docs/snippets/schemas/v3/searchContext.schema.mdx (2)

22-28: Schema definition looks correct.

The includeConnections property is properly defined as an optional array of strings with a clear description that aligns with the PR objectives for connection-based filtering.


42-48: Schema definition looks correct.

The excludeConnections property is properly defined as an optional array of strings with a clear description that complements the includeConnections functionality.

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

94-100: Schema definition is consistent and correct.

The includeConnections property in the SearchContext definition matches the documentation schema and maintains consistency across the codebase.


114-120: Schema definition is consistent and correct.

The excludeConnections property in the SearchContext definition matches the documentation schema and maintains consistency across the codebase.


224-230: Consistent schema definition in contexts pattern.

The includeConnections property is correctly duplicated in the contexts pattern properties to maintain schema consistency between standalone and nested SearchContext definitions.


244-250: Consistent schema definition in contexts pattern.

The excludeConnections property is correctly duplicated in the contexts pattern properties to maintain schema consistency between standalone and nested SearchContext definitions.

packages/shared/src/ee/syncSearchContexts.ts (3)

39-44: Correct implementation of optional include property.

The initialization change properly supports making the include property optional, allowing search contexts to rely solely on connection-based filtering. The conditional check and non-null assertion are appropriate.


80-107: Exclusion logic is correctly implemented.

The implementation properly filters out repositories belonging to excluded connections. The database query pattern is consistent with the inclusion logic, and the filtering approach using repo IDs is accurate.


39-107: Well-structured implementation of connection-based filtering.

The overall flow correctly implements the feature requirements:

  1. Maintains backwards compatibility with existing include/exclude patterns
  2. Properly integrates connection-based filtering
  3. Follows a logical sequence: include → exclude for both patterns and connections
  4. Preserves existing database synchronization logic

The implementation successfully extends search context functionality while maintaining code clarity and consistency.

@msukkari msukkari merged commit aebd8df into main Jul 27, 2025
7 checks passed
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