MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / syncSearchContexts

Function syncSearchContexts

packages/backend/src/ee/syncSearchContexts.ts:16–217  ·  view source on GitHub ↗
(params: SyncSearchContextsParams)

Source from the content-addressed store, hash-verified

14}
15
16export const syncSearchContexts = async (params: SyncSearchContextsParams) => {
17 const { contexts, orgId, db } = params;
18
19 if (!await hasEntitlement("search-contexts")) {
20 if (contexts) {
21 logger.warn(`Skipping search context sync. Reason: "Search contexts are not supported in your current plan. For support, contact ${SOURCEBOT_SUPPORT_EMAIL}."`);
22 }
23 return false;
24 }
25
26 if (contexts) {
27 for (const [key, newContextConfig] of Object.entries(contexts)) {
28 const allRepos = await db.repo.findMany({
29 where: {
30 orgId,
31 },
32 select: {
33 id: true,
34 name: true,
35 metadata: true,
36 }
37 });
38
39 let newReposInContext: { id: number, name: string, metadata: unknown }[] = [];
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 metadata: true,
62 }
63 }
64 }
65 }
66 }
67 });
68
69 for (const connection of connections) {
70 newReposInContext = newReposInContext.concat(connection.repos.map(repo => repo.repo));
71 }
72 }
73

Callers 3

onJobCompletedMethod · 0.85
ConfigManagerClass · 0.85

Calls 1

hasEntitlementFunction · 0.50

Tested by

no test coverage detected