Skip to content

Commit aebd8df

Browse files
authored
feat(search_contexts): Add ability to include/exclude connections in search contexts (#399)
* implement connection filter for search contexts * changelog
1 parent 3e50469 commit aebd8df

File tree

9 files changed

+179
-26
lines changed

9 files changed

+179
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111
- Add search context to ask sourcebot context selector. [#397](https://github.com/sourcebot-dev/sourcebot/pull/397)
12+
- Add ability to include/exclude connection in search context. [#399](https://github.com/sourcebot-dev/sourcebot/pull/399)
1213

1314
### Fixed
1415
- Fixed multiple writes race condition on config file watcher. [#398](https://github.com/sourcebot-dev/sourcebot/pull/398)

docs/snippets/schemas/v3/index.schema.mdx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
]
9393
]
9494
},
95+
"includeConnections": {
96+
"type": "array",
97+
"description": "List of connections to include in the search context.",
98+
"items": {
99+
"type": "string"
100+
}
101+
},
95102
"exclude": {
96103
"type": "array",
97104
"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 @@
105112
]
106113
]
107114
},
115+
"excludeConnections": {
116+
"type": "array",
117+
"description": "List of connections to exclude from the search context.",
118+
"items": {
119+
"type": "string"
120+
}
121+
},
108122
"description": {
109123
"type": "string",
110124
"description": "Optional description of the search context that surfaces in the UI."
111125
}
112126
},
113-
"required": [
114-
"include"
115-
],
116127
"additionalProperties": false
117128
}
118129
},
@@ -211,6 +222,13 @@
211222
]
212223
]
213224
},
225+
"includeConnections": {
226+
"type": "array",
227+
"description": "List of connections to include in the search context.",
228+
"items": {
229+
"type": "string"
230+
}
231+
},
214232
"exclude": {
215233
"type": "array",
216234
"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 @@
224242
]
225243
]
226244
},
245+
"excludeConnections": {
246+
"type": "array",
247+
"description": "List of connections to exclude from the search context.",
248+
"items": {
249+
"type": "string"
250+
}
251+
},
227252
"description": {
228253
"type": "string",
229254
"description": "Optional description of the search context that surfaces in the UI."
230255
}
231256
},
232-
"required": [
233-
"include"
234-
],
235257
"additionalProperties": false
236258
}
237259
},

docs/snippets/schemas/v3/searchContext.schema.mdx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
]
2020
]
2121
},
22+
"includeConnections": {
23+
"type": "array",
24+
"description": "List of connections to include in the search context.",
25+
"items": {
26+
"type": "string"
27+
}
28+
},
2229
"exclude": {
2330
"type": "array",
2431
"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 @@
3239
]
3340
]
3441
},
42+
"excludeConnections": {
43+
"type": "array",
44+
"description": "List of connections to exclude from the search context.",
45+
"items": {
46+
"type": "string"
47+
}
48+
},
3549
"description": {
3650
"type": "string",
3751
"description": "Optional description of the search context that surfaces in the UI."
3852
}
3953
},
40-
"required": [
41-
"include"
42-
],
4354
"additionalProperties": false
4455
}
4556
```

packages/schemas/src/v3/index.schema.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ const schema = {
9191
]
9292
]
9393
},
94+
"includeConnections": {
95+
"type": "array",
96+
"description": "List of connections to include in the search context.",
97+
"items": {
98+
"type": "string"
99+
}
100+
},
94101
"exclude": {
95102
"type": "array",
96103
"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 = {
104111
]
105112
]
106113
},
114+
"excludeConnections": {
115+
"type": "array",
116+
"description": "List of connections to exclude from the search context.",
117+
"items": {
118+
"type": "string"
119+
}
120+
},
107121
"description": {
108122
"type": "string",
109123
"description": "Optional description of the search context that surfaces in the UI."
110124
}
111125
},
112-
"required": [
113-
"include"
114-
],
115126
"additionalProperties": false
116127
}
117128
},
@@ -210,6 +221,13 @@ const schema = {
210221
]
211222
]
212223
},
224+
"includeConnections": {
225+
"type": "array",
226+
"description": "List of connections to include in the search context.",
227+
"items": {
228+
"type": "string"
229+
}
230+
},
213231
"exclude": {
214232
"type": "array",
215233
"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 = {
223241
]
224242
]
225243
},
244+
"excludeConnections": {
245+
"type": "array",
246+
"description": "List of connections to exclude from the search context.",
247+
"items": {
248+
"type": "string"
249+
}
250+
},
226251
"description": {
227252
"type": "string",
228253
"description": "Optional description of the search context that surfaces in the UI."
229254
}
230255
},
231-
"required": [
232-
"include"
233-
],
234256
"additionalProperties": false
235257
}
236258
},

packages/schemas/src/v3/index.type.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,19 @@ export interface SearchContext {
114114
/**
115115
* 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.
116116
*/
117-
include: string[];
117+
include?: string[];
118+
/**
119+
* List of connections to include in the search context.
120+
*/
121+
includeConnections?: string[];
118122
/**
119123
* 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.
120124
*/
121125
exclude?: string[];
126+
/**
127+
* List of connections to exclude from the search context.
128+
*/
129+
excludeConnections?: string[];
122130
/**
123131
* Optional description of the search context that surfaces in the UI.
124132
*/

packages/schemas/src/v3/searchContext.schema.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ const schema = {
1818
]
1919
]
2020
},
21+
"includeConnections": {
22+
"type": "array",
23+
"description": "List of connections to include in the search context.",
24+
"items": {
25+
"type": "string"
26+
}
27+
},
2128
"exclude": {
2229
"type": "array",
2330
"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 = {
3138
]
3239
]
3340
},
41+
"excludeConnections": {
42+
"type": "array",
43+
"description": "List of connections to exclude from the search context.",
44+
"items": {
45+
"type": "string"
46+
}
47+
},
3448
"description": {
3549
"type": "string",
3650
"description": "Optional description of the search context that surfaces in the UI."
3751
}
3852
},
39-
"required": [
40-
"include"
41-
],
4253
"additionalProperties": false
4354
} as const;
4455
export { schema as searchContextSchema };

packages/schemas/src/v3/searchContext.type.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ export interface SearchContext {
77
/**
88
* 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.
99
*/
10-
include: string[];
10+
include?: string[];
11+
/**
12+
* List of connections to include in the search context.
13+
*/
14+
includeConnections?: string[];
1115
/**
1216
* 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.
1317
*/
1418
exclude?: string[];
19+
/**
20+
* List of connections to exclude from the search context.
21+
*/
22+
excludeConnections?: string[];
1523
/**
1624
* Optional description of the search context that surfaces in the UI.
1725
*/

packages/shared/src/ee/syncSearchContexts.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,39 @@ export const syncSearchContexts = async (params: SyncSearchContextsParams) => {
3636
}
3737
});
3838

39-
let newReposInContext = allRepos.filter(repo => {
40-
return micromatch.isMatch(repo.name, newContextConfig.include);
41-
});
39+
let newReposInContext: { id: number, name: string }[] = [];
40+
if(newContextConfig.include) {
41+
newReposInContext = allRepos.filter(repo => {
42+
return micromatch.isMatch(repo.name, newContextConfig.include!);
43+
});
44+
}
45+
46+
if(newContextConfig.includeConnections) {
47+
const connections = await db.connection.findMany({
48+
where: {
49+
orgId,
50+
name: {
51+
in: newContextConfig.includeConnections,
52+
}
53+
},
54+
include: {
55+
repos: {
56+
select: {
57+
repo: {
58+
select: {
59+
id: true,
60+
name: true,
61+
}
62+
}
63+
}
64+
}
65+
}
66+
});
67+
68+
for (const connection of connections) {
69+
newReposInContext = newReposInContext.concat(connection.repos.map(repo => repo.repo));
70+
}
71+
}
4272

4373
if (newContextConfig.exclude) {
4474
const exclude = newContextConfig.exclude;
@@ -47,6 +77,35 @@ export const syncSearchContexts = async (params: SyncSearchContextsParams) => {
4777
});
4878
}
4979

80+
if (newContextConfig.excludeConnections) {
81+
const connections = await db.connection.findMany({
82+
where: {
83+
orgId,
84+
name: {
85+
in: newContextConfig.excludeConnections,
86+
}
87+
},
88+
include: {
89+
repos: {
90+
select: {
91+
repo: {
92+
select: {
93+
id: true,
94+
name: true,
95+
}
96+
}
97+
}
98+
}
99+
}
100+
});
101+
102+
for (const connection of connections) {
103+
newReposInContext = newReposInContext.filter(repo => {
104+
return !connection.repos.map(r => r.repo.id).includes(repo.id);
105+
});
106+
}
107+
}
108+
50109
const currentReposInContext = (await db.searchContext.findUnique({
51110
where: {
52111
name_orgId: {

schemas/v3/searchContext.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
]
1818
]
1919
},
20+
"includeConnections": {
21+
"type": "array",
22+
"description": "List of connections to include in the search context.",
23+
"items": {
24+
"type": "string"
25+
}
26+
},
2027
"exclude": {
2128
"type": "array",
2229
"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 @@
3037
]
3138
]
3239
},
40+
"excludeConnections": {
41+
"type": "array",
42+
"description": "List of connections to exclude from the search context.",
43+
"items": {
44+
"type": "string"
45+
}
46+
},
3347
"description": {
3448
"type": "string",
3549
"description": "Optional description of the search context that surfaces in the UI."
3650
}
3751
},
38-
"required": [
39-
"include"
40-
],
4152
"additionalProperties": false
4253
}

0 commit comments

Comments
 (0)