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

* implement connection filter for search contexts

* changelog
This commit is contained in:
Michael Sukkarieh 2025-07-27 10:11:58 -07:00 committed by GitHub
parent 3e50469cf7
commit aebd8df193
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 179 additions and 26 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Add search context to ask sourcebot context selector. [#397](https://github.com/sourcebot-dev/sourcebot/pull/397) - 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
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398) - Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)

View file

@ -92,6 +92,13 @@
] ]
] ]
}, },
"includeConnections": {
"type": "array",
"description": "List of connections to include in the search context.",
"items": {
"type": "string"
}
},
"exclude": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "additionalProperties": false
} }
}, },
@ -211,6 +222,13 @@
] ]
] ]
}, },
"includeConnections": {
"type": "array",
"description": "List of connections to include in the search context.",
"items": {
"type": "string"
}
},
"exclude": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "additionalProperties": false
} }
}, },

View file

@ -19,6 +19,13 @@
] ]
] ]
}, },
"includeConnections": {
"type": "array",
"description": "List of connections to include in the search context.",
"items": {
"type": "string"
}
},
"exclude": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "additionalProperties": false
} }
``` ```

View file

@ -91,6 +91,13 @@ const schema = {
] ]
] ]
}, },
"includeConnections": {
"type": "array",
"description": "List of connections to include in the search context.",
"items": {
"type": "string"
}
},
"exclude": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "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": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "additionalProperties": false
} }
}, },

View file

@ -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. * 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. * 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[]; exclude?: string[];
/**
* List of connections to exclude from the search context.
*/
excludeConnections?: string[];
/** /**
* Optional description of the search context that surfaces in the UI. * Optional description of the search context that surfaces in the UI.
*/ */

View file

@ -18,6 +18,13 @@ const schema = {
] ]
] ]
}, },
"includeConnections": {
"type": "array",
"description": "List of connections to include in the search context.",
"items": {
"type": "string"
}
},
"exclude": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "additionalProperties": false
} as const; } as const;
export { schema as searchContextSchema }; export { schema as searchContextSchema };

View file

@ -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. * 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. * 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[]; exclude?: string[];
/**
* List of connections to exclude from the search context.
*/
excludeConnections?: string[];
/** /**
* Optional description of the search context that surfaces in the UI. * Optional description of the search context that surfaces in the UI.
*/ */

View file

@ -36,9 +36,39 @@ export const syncSearchContexts = async (params: SyncSearchContextsParams) => {
} }
}); });
let newReposInContext = allRepos.filter(repo => { let newReposInContext: { id: number, name: string }[] = [];
return micromatch.isMatch(repo.name, newContextConfig.include); 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) { if (newContextConfig.exclude) {
const exclude = 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({ const currentReposInContext = (await db.searchContext.findUnique({
where: { where: {
name_orgId: { name_orgId: {

View file

@ -17,6 +17,13 @@
] ]
] ]
}, },
"includeConnections": {
"type": "array",
"description": "List of connections to include in the search context.",
"items": {
"type": "string"
}
},
"exclude": { "exclude": {
"type": "array", "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.", "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": { "description": {
"type": "string", "type": "string",
"description": "Optional description of the search context that surfaces in the UI." "description": "Optional description of the search context that surfaces in the UI."
} }
}, },
"required": [
"include"
],
"additionalProperties": false "additionalProperties": false
} }