mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-11 20:05:25 +00:00
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:
parent
3e50469cf7
commit
aebd8df193
9 changed files with 179 additions and 26 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in a new issue