Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 28 additions & 6 deletions docs/snippets/schemas/v3/index.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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
}
},
Expand Down Expand Up @@ -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.",
Expand All @@ -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
}
},
Expand Down
17 changes: 14 additions & 3 deletions docs/snippets/schemas/v3/searchContext.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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
}
```
34 changes: 28 additions & 6 deletions packages/schemas/src/v3/index.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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
}
},
Expand Down Expand Up @@ -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.",
Expand All @@ -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
}
},
Expand Down
10 changes: 9 additions & 1 deletion packages/schemas/src/v3/index.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
17 changes: 14 additions & 3 deletions packages/schemas/src/v3/searchContext.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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 };
10 changes: 9 additions & 1 deletion packages/schemas/src/v3/searchContext.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
65 changes: 62 additions & 3 deletions packages/shared/src/ee/syncSearchContexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: {
Expand Down
17 changes: 14 additions & 3 deletions schemas/v3/searchContext.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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
}