diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e792039..ba12ac52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add search context to ask sourcebot context selector. [#397](https://github.com/sourcebot-dev/sourcebot/pull/397) +- Add ability to include/exclude connection in search context. [#399](https://github.com/sourcebot-dev/sourcebot/pull/399) ### Fixed - Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398) diff --git a/docs/snippets/schemas/v3/index.schema.mdx b/docs/snippets/schemas/v3/index.schema.mdx index 51f483af..0b284164 100644 --- a/docs/snippets/schemas/v3/index.schema.mdx +++ b/docs/snippets/schemas/v3/index.schema.mdx @@ -92,6 +92,13 @@ ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -105,14 +112,18 @@ ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } }, @@ -211,6 +222,13 @@ ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -224,14 +242,18 @@ ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } }, diff --git a/docs/snippets/schemas/v3/searchContext.schema.mdx b/docs/snippets/schemas/v3/searchContext.schema.mdx index 01477bef..2f0849cf 100644 --- a/docs/snippets/schemas/v3/searchContext.schema.mdx +++ b/docs/snippets/schemas/v3/searchContext.schema.mdx @@ -19,6 +19,13 @@ ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -32,14 +39,18 @@ ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } ``` diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index e5bdbf1f..d1a29dc7 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -91,6 +91,13 @@ const schema = { ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -104,14 +111,18 @@ const schema = { ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } }, @@ -210,6 +221,13 @@ const schema = { ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -223,14 +241,18 @@ const schema = { ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } }, diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index 9f5fb870..b22b88ec 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -114,11 +114,19 @@ export interface SearchContext { /** * List of repositories to include in the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported. */ - include: string[]; + include?: string[]; + /** + * List of connections to include in the search context. + */ + includeConnections?: string[]; /** * List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported. */ exclude?: string[]; + /** + * List of connections to exclude from the search context. + */ + excludeConnections?: string[]; /** * Optional description of the search context that surfaces in the UI. */ diff --git a/packages/schemas/src/v3/searchContext.schema.ts b/packages/schemas/src/v3/searchContext.schema.ts index c36cb801..7d97b94f 100644 --- a/packages/schemas/src/v3/searchContext.schema.ts +++ b/packages/schemas/src/v3/searchContext.schema.ts @@ -18,6 +18,13 @@ const schema = { ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -31,14 +38,18 @@ const schema = { ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } as const; export { schema as searchContextSchema }; \ No newline at end of file diff --git a/packages/schemas/src/v3/searchContext.type.ts b/packages/schemas/src/v3/searchContext.type.ts index 255b5a03..ca2cb1b2 100644 --- a/packages/schemas/src/v3/searchContext.type.ts +++ b/packages/schemas/src/v3/searchContext.type.ts @@ -7,11 +7,19 @@ export interface SearchContext { /** * List of repositories to include in the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported. */ - include: string[]; + include?: string[]; + /** + * List of connections to include in the search context. + */ + includeConnections?: string[]; /** * List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported. */ exclude?: string[]; + /** + * List of connections to exclude from the search context. + */ + excludeConnections?: string[]; /** * Optional description of the search context that surfaces in the UI. */ diff --git a/packages/shared/src/ee/syncSearchContexts.ts b/packages/shared/src/ee/syncSearchContexts.ts index 7ab59b35..8dd932ae 100644 --- a/packages/shared/src/ee/syncSearchContexts.ts +++ b/packages/shared/src/ee/syncSearchContexts.ts @@ -36,9 +36,39 @@ export const syncSearchContexts = async (params: SyncSearchContextsParams) => { } }); - let newReposInContext = allRepos.filter(repo => { - return micromatch.isMatch(repo.name, newContextConfig.include); - }); + let newReposInContext: { id: number, name: string }[] = []; + if(newContextConfig.include) { + newReposInContext = allRepos.filter(repo => { + return micromatch.isMatch(repo.name, newContextConfig.include!); + }); + } + + if(newContextConfig.includeConnections) { + const connections = await db.connection.findMany({ + where: { + orgId, + name: { + in: newContextConfig.includeConnections, + } + }, + include: { + repos: { + select: { + repo: { + select: { + id: true, + name: true, + } + } + } + } + } + }); + + for (const connection of connections) { + newReposInContext = newReposInContext.concat(connection.repos.map(repo => repo.repo)); + } + } if (newContextConfig.exclude) { const exclude = newContextConfig.exclude; @@ -47,6 +77,35 @@ export const syncSearchContexts = async (params: SyncSearchContextsParams) => { }); } + if (newContextConfig.excludeConnections) { + const connections = await db.connection.findMany({ + where: { + orgId, + name: { + in: newContextConfig.excludeConnections, + } + }, + include: { + repos: { + select: { + repo: { + select: { + id: true, + name: true, + } + } + } + } + } + }); + + for (const connection of connections) { + newReposInContext = newReposInContext.filter(repo => { + return !connection.repos.map(r => r.repo.id).includes(repo.id); + }); + } + } + const currentReposInContext = (await db.searchContext.findUnique({ where: { name_orgId: { diff --git a/schemas/v3/searchContext.json b/schemas/v3/searchContext.json index 70e3087b..bdc7bf65 100644 --- a/schemas/v3/searchContext.json +++ b/schemas/v3/searchContext.json @@ -17,6 +17,13 @@ ] ] }, + "includeConnections": { + "type": "array", + "description": "List of connections to include in the search context.", + "items": { + "type": "string" + } + }, "exclude": { "type": "array", "description": "List of repositories to exclude from the search context. Expected to be formatted as a URL without any leading http(s):// prefix (e.g., 'github.com/sourcebot-dev/sourcebot'). Glob patterns are supported.", @@ -30,13 +37,17 @@ ] ] }, + "excludeConnections": { + "type": "array", + "description": "List of connections to exclude from the search context.", + "items": { + "type": "string" + } + }, "description": { "type": "string", "description": "Optional description of the search context that surfaces in the UI." } }, - "required": [ - "include" - ], "additionalProperties": false } \ No newline at end of file