Skip to content

Commit ad17a4f

Browse files
Merge pull request #3570 from github/robertbrignull/disable_top1000
Hide system defined lists when enterprise URI is set
2 parents f17319a + 26ec371 commit ad17a4f

File tree

12 files changed

+212
-24
lines changed

12 files changed

+212
-24
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ export async function setRemoteControllerRepo(repo: string | undefined) {
569569

570570
export interface VariantAnalysisConfig {
571571
controllerRepo: string | undefined;
572+
showSystemDefinedRepositoryLists: boolean;
572573
onDidChangeConfiguration?: Event<void>;
573574
}
574575

@@ -578,14 +579,18 @@ export class VariantAnalysisConfigListener
578579
{
579580
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
580581
this.handleDidChangeConfigurationForRelevantSettings(
581-
[VARIANT_ANALYSIS_SETTING],
582+
[VARIANT_ANALYSIS_SETTING, VSCODE_GITHUB_ENTERPRISE_URI_SETTING],
582583
e,
583584
);
584585
}
585586

586587
public get controllerRepo(): string | undefined {
587588
return getRemoteControllerRepo();
588589
}
590+
591+
public get showSystemDefinedRepositoryLists(): boolean {
592+
return !hasEnterpriseUri();
593+
}
589594
}
590595

591596
const VARIANT_ANALYSIS_FILTER_RESULTS = new Setting(

extensions/ql-vscode/src/databases/db-manager.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "./db-item-selection";
1717
import { createRemoteTree } from "./db-tree-creator";
1818
import type { DbConfigValidationError } from "./db-validation-errors";
19+
import type { VariantAnalysisConfig } from "../config";
1920

2021
export class DbManager extends DisposableObject {
2122
public readonly onDbItemsChanged: AppEvent<void>;
@@ -25,6 +26,7 @@ export class DbManager extends DisposableObject {
2526
constructor(
2627
private readonly app: App,
2728
private readonly dbConfigStore: DbConfigStore,
29+
private readonly variantAnalysisConfigListener: VariantAnalysisConfig,
2830
) {
2931
super();
3032

@@ -36,6 +38,10 @@ export class DbManager extends DisposableObject {
3638
this.dbConfigStore.onDidChangeConfig(() => {
3739
this.onDbItemsChangesEventEmitter.fire();
3840
});
41+
42+
this.variantAnalysisConfigListener.onDidChangeConfiguration?.(() => {
43+
this.onDbItemsChangesEventEmitter.fire();
44+
});
3945
}
4046

4147
public getSelectedDbItem(): DbItem | undefined {
@@ -56,7 +62,11 @@ export class DbManager extends DisposableObject {
5662

5763
const expandedItems = this.getExpandedItems();
5864

59-
const remoteTree = createRemoteTree(configResult.value, expandedItems);
65+
const remoteTree = createRemoteTree(
66+
configResult.value,
67+
this.variantAnalysisConfigListener,
68+
expandedItems,
69+
);
6070
return ValueResult.ok(remoteTree.children);
6171
}
6272

extensions/ql-vscode/src/databases/db-module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DbManager } from "./db-manager";
77
import { DbPanel } from "./ui/db-panel";
88
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
99
import type { DatabasePanelCommands } from "../common/commands";
10+
import { VariantAnalysisConfigListener } from "../config";
1011

1112
export class DbModule extends DisposableObject {
1213
public readonly dbManager: DbManager;
@@ -17,7 +18,13 @@ export class DbModule extends DisposableObject {
1718
super();
1819

1920
this.dbConfigStore = new DbConfigStore(app);
20-
this.dbManager = this.push(new DbManager(app, this.dbConfigStore));
21+
this.dbManager = this.push(
22+
new DbManager(
23+
app,
24+
this.dbConfigStore,
25+
new VariantAnalysisConfigListener(),
26+
),
27+
);
2128
}
2229

2330
public static async initialize(app: App): Promise<DbModule> {

extensions/ql-vscode/src/databases/db-tree-creator.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { VariantAnalysisConfig } from "../config";
12
import type { DbConfig, RemoteRepositoryList } from "./config/db-config";
23
import { SelectedDbItemKind } from "./config/db-config";
34
import type {
@@ -13,13 +14,17 @@ import { ExpandedDbItemKind } from "./db-item-expansion";
1314

1415
export function createRemoteTree(
1516
dbConfig: DbConfig,
17+
variantAnalysisConfig: VariantAnalysisConfig,
1618
expandedItems: ExpandedDbItem[],
1719
): RootRemoteDbItem {
18-
const systemDefinedLists = [
19-
createSystemDefinedList(10, dbConfig),
20-
createSystemDefinedList(100, dbConfig),
21-
createSystemDefinedList(1000, dbConfig),
22-
];
20+
const systemDefinedLists =
21+
variantAnalysisConfig.showSystemDefinedRepositoryLists
22+
? [
23+
createSystemDefinedList(10, dbConfig),
24+
createSystemDefinedList(100, dbConfig),
25+
createSystemDefinedList(1000, dbConfig),
26+
]
27+
: [];
2328

2429
const userDefinedRepoLists =
2530
dbConfig.databases.variantAnalysis.repositoryLists.map((r) =>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { VariantAnalysisConfig } from "../../src/config";
2+
3+
export function createMockVariantAnalysisConfig(): VariantAnalysisConfig {
4+
return {
5+
controllerRepo: "foo/bar",
6+
showSystemDefinedRepositoryLists: true,
7+
onDidChangeConfiguration: jest.fn(),
8+
};
9+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { DbManager } from "../../../src/databases/db-manager";
2424
import { createDbConfig } from "../../factories/db-config-factories";
2525
import { createRemoteUserDefinedListDbItem } from "../../factories/db-item-factories";
2626
import { createMockApp } from "../../__mocks__/appMock";
27+
import { createMockVariantAnalysisConfig } from "../../factories/config";
2728

2829
// Note: Although these are "unit tests" (i.e. not integrating with VS Code), they do
2930
// test the interaction/"integration" between the DbManager and the DbConfigStore.
@@ -46,7 +47,11 @@ describe("db manager", () => {
4647
// We don't need to watch changes to the config file in these tests, so we
4748
// pass `false` to the dbConfigStore constructor.
4849
dbConfigStore = new DbConfigStore(app, false);
49-
dbManager = new DbManager(app, dbConfigStore);
50+
dbManager = new DbManager(
51+
app,
52+
dbConfigStore,
53+
createMockVariantAnalysisConfig(),
54+
);
5055
await ensureDir(tempWorkspaceStoragePath);
5156

5257
dbConfigFilePath = join(

extensions/ql-vscode/test/unit-tests/databases/db-tree-creator.test.ts

Lines changed: 132 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ import type { ExpandedDbItem } from "../../../src/databases/db-item-expansion";
1010
import { ExpandedDbItemKind } from "../../../src/databases/db-item-expansion";
1111
import { createRemoteTree } from "../../../src/databases/db-tree-creator";
1212
import { createDbConfig } from "../../factories/db-config-factories";
13+
import { createMockVariantAnalysisConfig } from "../../factories/config";
1314

1415
describe("db tree creator", () => {
16+
const defaultVariantAnalysisConfig = createMockVariantAnalysisConfig();
17+
1518
describe("createRemoteTree", () => {
1619
it("should build root node and system defined lists", () => {
1720
const dbConfig = createDbConfig();
1821

19-
const dbTreeRoot = createRemoteTree(dbConfig, []);
22+
const dbTreeRoot = createRemoteTree(
23+
dbConfig,
24+
defaultVariantAnalysisConfig,
25+
[],
26+
);
2027

2128
expect(dbTreeRoot).toBeTruthy();
2229
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -45,6 +52,24 @@ describe("db tree creator", () => {
4552
});
4653
});
4754

55+
it("displays empty list when no remote user defined list nodes and system defined lists are disabled", () => {
56+
const dbConfig = createDbConfig();
57+
58+
const dbTreeRoot = createRemoteTree(
59+
dbConfig,
60+
{
61+
...defaultVariantAnalysisConfig,
62+
showSystemDefinedRepositoryLists: false,
63+
},
64+
[],
65+
);
66+
67+
expect(dbTreeRoot).toBeTruthy();
68+
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
69+
expect(dbTreeRoot.expanded).toBe(false);
70+
expect(dbTreeRoot.children.length).toBe(0);
71+
});
72+
4873
it("should create remote user defined list nodes", () => {
4974
const dbConfig = createDbConfig({
5075
remoteLists: [
@@ -59,10 +84,15 @@ describe("db tree creator", () => {
5984
],
6085
});
6186

62-
const dbTreeRoot = createRemoteTree(dbConfig, []);
87+
const dbTreeRoot = createRemoteTree(
88+
dbConfig,
89+
defaultVariantAnalysisConfig,
90+
[],
91+
);
6392

6493
expect(dbTreeRoot).toBeTruthy();
6594
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
95+
expect(dbTreeRoot.children.length).toBe(5);
6696
const repositoryListNodes = dbTreeRoot.children.filter(
6797
isRemoteUserDefinedListDbItem,
6898
);
@@ -102,12 +132,76 @@ describe("db tree creator", () => {
102132
});
103133
});
104134

135+
it("shows only user defined list nodes when system defined lists are disabled", () => {
136+
const dbConfig = createDbConfig({
137+
remoteLists: [
138+
{
139+
name: "my-list-1",
140+
repositories: ["owner1/repo1", "owner1/repo2", "owner2/repo1"],
141+
},
142+
{
143+
name: "my-list-2",
144+
repositories: ["owner3/repo1", "owner3/repo2", "owner4/repo1"],
145+
},
146+
],
147+
});
148+
149+
const dbTreeRoot = createRemoteTree(
150+
dbConfig,
151+
{
152+
...defaultVariantAnalysisConfig,
153+
showSystemDefinedRepositoryLists: false,
154+
},
155+
[],
156+
);
157+
158+
expect(dbTreeRoot).toBeTruthy();
159+
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
160+
expect(dbTreeRoot.children.length).toBe(2);
161+
expect(dbTreeRoot.children[0]).toEqual({
162+
kind: DbItemKind.RemoteUserDefinedList,
163+
selected: false,
164+
expanded: false,
165+
listName: dbConfig.databases.variantAnalysis.repositoryLists[0].name,
166+
repos:
167+
dbConfig.databases.variantAnalysis.repositoryLists[0].repositories.map(
168+
(repo) => ({
169+
kind: DbItemKind.RemoteRepo,
170+
selected: false,
171+
repoFullName: repo,
172+
parentListName:
173+
dbConfig.databases.variantAnalysis.repositoryLists[0].name,
174+
}),
175+
),
176+
});
177+
expect(dbTreeRoot.children[1]).toEqual({
178+
kind: DbItemKind.RemoteUserDefinedList,
179+
selected: false,
180+
expanded: false,
181+
listName: dbConfig.databases.variantAnalysis.repositoryLists[1].name,
182+
repos:
183+
dbConfig.databases.variantAnalysis.repositoryLists[1].repositories.map(
184+
(repo) => ({
185+
kind: DbItemKind.RemoteRepo,
186+
selected: false,
187+
repoFullName: repo,
188+
parentListName:
189+
dbConfig.databases.variantAnalysis.repositoryLists[1].name,
190+
}),
191+
),
192+
});
193+
});
194+
105195
it("should create remote owner nodes", () => {
106196
const dbConfig: DbConfig = createDbConfig({
107197
remoteOwners: ["owner1", "owner2"],
108198
});
109199

110-
const dbTreeRoot = createRemoteTree(dbConfig, []);
200+
const dbTreeRoot = createRemoteTree(
201+
dbConfig,
202+
defaultVariantAnalysisConfig,
203+
[],
204+
);
111205

112206
expect(dbTreeRoot).toBeTruthy();
113207
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -131,7 +225,11 @@ describe("db tree creator", () => {
131225
remoteRepos: ["owner1/repo1", "owner1/repo2", "owner2/repo1"],
132226
});
133227

134-
const dbTreeRoot = createRemoteTree(dbConfig, []);
228+
const dbTreeRoot = createRemoteTree(
229+
dbConfig,
230+
defaultVariantAnalysisConfig,
231+
[],
232+
);
135233

136234
expect(dbTreeRoot).toBeTruthy();
137235
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -170,7 +268,11 @@ describe("db tree creator", () => {
170268
},
171269
});
172270

173-
const dbTreeRoot = createRemoteTree(dbConfig, []);
271+
const dbTreeRoot = createRemoteTree(
272+
dbConfig,
273+
defaultVariantAnalysisConfig,
274+
[],
275+
);
174276

175277
expect(dbTreeRoot).toBeTruthy();
176278
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -191,7 +293,11 @@ describe("db tree creator", () => {
191293
},
192294
});
193295

194-
const dbTreeRoot = createRemoteTree(dbConfig, []);
296+
const dbTreeRoot = createRemoteTree(
297+
dbConfig,
298+
defaultVariantAnalysisConfig,
299+
[],
300+
);
195301

196302
expect(dbTreeRoot).toBeTruthy();
197303
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -213,7 +319,11 @@ describe("db tree creator", () => {
213319
},
214320
});
215321

216-
const dbTreeRoot = createRemoteTree(dbConfig, []);
322+
const dbTreeRoot = createRemoteTree(
323+
dbConfig,
324+
defaultVariantAnalysisConfig,
325+
[],
326+
);
217327

218328
expect(dbTreeRoot).toBeTruthy();
219329
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -240,7 +350,11 @@ describe("db tree creator", () => {
240350
},
241351
});
242352

243-
const dbTreeRoot = createRemoteTree(dbConfig, []);
353+
const dbTreeRoot = createRemoteTree(
354+
dbConfig,
355+
defaultVariantAnalysisConfig,
356+
[],
357+
);
244358

245359
expect(dbTreeRoot).toBeTruthy();
246360

@@ -265,7 +379,11 @@ describe("db tree creator", () => {
265379
},
266380
];
267381

268-
const dbTreeRoot = createRemoteTree(dbConfig, expanded);
382+
const dbTreeRoot = createRemoteTree(
383+
dbConfig,
384+
defaultVariantAnalysisConfig,
385+
expanded,
386+
);
269387

270388
expect(dbTreeRoot).toBeTruthy();
271389
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);
@@ -291,7 +409,11 @@ describe("db tree creator", () => {
291409
},
292410
];
293411

294-
const dbTreeRoot = createRemoteTree(dbConfig, expanded);
412+
const dbTreeRoot = createRemoteTree(
413+
dbConfig,
414+
defaultVariantAnalysisConfig,
415+
expanded,
416+
);
295417

296418
expect(dbTreeRoot).toBeTruthy();
297419
expect(dbTreeRoot.kind).toBe(DbItemKind.RootRemote);

0 commit comments

Comments
 (0)