Skip to content

Commit dd01832

Browse files
committed
Add no more than 1000 items to a list plus tests
1 parent f76d7bf commit dd01832

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ export class DbConfigStore extends DisposableObject {
165165
...new Set(parent.repositories),
166166
...new Set(repoNwoList),
167167
]);
168-
parent.repositories = [...newRepositoriesList];
169168

169+
if (newRepositoriesList.size > 1000) {
170+
parent.repositories = [...Array.from(newRepositoriesList).slice(0, 1000)];
171+
} else {
172+
parent.repositories = [...newRepositoriesList];
173+
}
170174
await this.writeConfig(config);
171175
}
172176

extensions/ql-vscode/test/unit-tests/databases/config/db-config-store.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,80 @@ describe("db config store", () => {
241241
configStore.dispose();
242242
});
243243

244+
it("should add unique remote repositories to the correct list", async () => {
245+
// Initial set up
246+
const dbConfig = createDbConfig({
247+
remoteLists: [
248+
{
249+
name: "list1",
250+
repositories: ["owner/repo1"],
251+
},
252+
],
253+
});
254+
255+
const configStore = await initializeConfig(dbConfig, configPath, app);
256+
expect(
257+
configStore.getConfig().value.databases.variantAnalysis
258+
.repositoryLists[0],
259+
).toEqual({
260+
name: "list1",
261+
repositories: ["owner/repo1"],
262+
});
263+
264+
// Add
265+
await configStore.addRemoteReposToList(
266+
["owner/repo1", "owner/repo2"],
267+
"list1",
268+
);
269+
270+
// Read the config file
271+
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
272+
273+
// Check that the config file has been updated
274+
const updatedRemoteDbs = updatedDbConfig.databases.variantAnalysis;
275+
expect(updatedRemoteDbs.repositories).toHaveLength(0);
276+
expect(updatedRemoteDbs.repositoryLists).toHaveLength(1);
277+
expect(updatedRemoteDbs.repositoryLists[0]).toEqual({
278+
name: "list1",
279+
repositories: ["owner/repo1", "owner/repo2"],
280+
});
281+
282+
configStore.dispose();
283+
});
284+
285+
it("should add no more than 1000 repositories to a list", async () => {
286+
// Initial set up
287+
const dbConfig = createDbConfig({
288+
remoteLists: [
289+
{
290+
name: "list1",
291+
repositories: [],
292+
},
293+
],
294+
});
295+
296+
const configStore = await initializeConfig(dbConfig, configPath, app);
297+
298+
// Add
299+
await configStore.addRemoteReposToList(
300+
[...Array(1001).keys()].map((i) => `owner/db${i}`),
301+
"list1",
302+
);
303+
304+
// Read the config file
305+
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
306+
307+
// Check that the config file has been updated
308+
const updatedRemoteDbs = updatedDbConfig.databases.variantAnalysis;
309+
expect(updatedRemoteDbs.repositories).toHaveLength(0);
310+
expect(updatedRemoteDbs.repositoryLists).toHaveLength(1);
311+
expect(updatedRemoteDbs.repositoryLists[0].repositories).toHaveLength(
312+
1000,
313+
);
314+
315+
configStore.dispose();
316+
});
317+
244318
it("should add a remote owner", async () => {
245319
// Initial set up
246320
const dbConfig = createDbConfig();

0 commit comments

Comments
 (0)