Skip to content

Commit 4dba169

Browse files
authored
Support new DB config format in "copy repo list" function (#1927)
1 parent afc6ce5 commit 4dba169

2 files changed

Lines changed: 131 additions & 47 deletions

File tree

extensions/ql-vscode/src/remote-queries/variant-analysis-manager.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
} from "../pure/variant-analysis-filter-sort";
6161
import { URLSearchParams } from "url";
6262
import { DbManager } from "../databases/db-manager";
63+
import { isNewQueryRunExperienceEnabled } from "../config";
6364

6465
export class VariantAnalysisManager
6566
extends DisposableObject
@@ -605,12 +606,25 @@ export class VariantAnalysisManager
605606
return;
606607
}
607608

608-
const text = [
609-
'"new-repo-list": [',
610-
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
611-
` "${fullNames[fullNames.length - 1]}"`,
612-
"]",
613-
];
609+
let text: string[];
610+
if (isNewQueryRunExperienceEnabled()) {
611+
text = [
612+
"{",
613+
` "name": "new-repo-list",`,
614+
` "repositories": [`,
615+
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
616+
` "${fullNames[fullNames.length - 1]}"`,
617+
` ]`,
618+
"}",
619+
];
620+
} else {
621+
text = [
622+
'"new-repo-list": [',
623+
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
624+
` "${fullNames[fullNames.length - 1]}"`,
625+
"]",
626+
];
627+
}
614628

615629
await env.clipboard.writeText(text.join(EOL));
616630
}

extensions/ql-vscode/test/vscode-tests/cli-integration/remote-queries/variant-analysis-manager.test.ts

Lines changed: 111 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,61 +1009,131 @@ describe("Variant Analysis Manager", () => {
10091009
expect(writeTextStub).toBeCalledTimes(1);
10101010
});
10111011

1012-
it("should be valid JSON when put in object", async () => {
1013-
await variantAnalysisManager.copyRepoListToClipboard(
1014-
variantAnalysis.id,
1015-
);
1012+
describe("newQueryRunExperience true", () => {
1013+
beforeEach(() => {
1014+
jest
1015+
.spyOn(config, "isNewQueryRunExperienceEnabled")
1016+
.mockReturnValue(true);
1017+
});
1018+
1019+
it("should be valid JSON when put in object", async () => {
1020+
await variantAnalysisManager.copyRepoListToClipboard(
1021+
variantAnalysis.id,
1022+
);
10161023

1017-
const text = writeTextStub.mock.calls[0][0];
1024+
const text = writeTextStub.mock.calls[0][0];
10181025

1019-
const parsed = JSON.parse(`{${text}}`);
1026+
const parsed = JSON.parse(`${text}`);
10201027

1021-
expect(parsed).toEqual({
1022-
"new-repo-list": [
1023-
scannedRepos[4].repository.fullName,
1024-
scannedRepos[2].repository.fullName,
1025-
scannedRepos[0].repository.fullName,
1026-
],
1028+
expect(parsed).toEqual({
1029+
name: "new-repo-list",
1030+
repositories: [
1031+
scannedRepos[4].repository.fullName,
1032+
scannedRepos[2].repository.fullName,
1033+
scannedRepos[0].repository.fullName,
1034+
],
1035+
});
10271036
});
1028-
});
10291037

1030-
it("should use the sort key", async () => {
1031-
await variantAnalysisManager.copyRepoListToClipboard(
1032-
variantAnalysis.id,
1033-
{
1034-
...defaultFilterSortState,
1035-
sortKey: SortKey.ResultsCount,
1036-
},
1037-
);
1038+
it("should use the sort key", async () => {
1039+
await variantAnalysisManager.copyRepoListToClipboard(
1040+
variantAnalysis.id,
1041+
{
1042+
...defaultFilterSortState,
1043+
sortKey: SortKey.ResultsCount,
1044+
},
1045+
);
10381046

1039-
const text = writeTextStub.mock.calls[0][0];
1047+
const text = writeTextStub.mock.calls[0][0];
10401048

1041-
const parsed = JSON.parse(`{${text}}`);
1049+
const parsed = JSON.parse(`${text}`);
10421050

1043-
expect(parsed).toEqual({
1044-
"new-repo-list": [
1045-
scannedRepos[2].repository.fullName,
1046-
scannedRepos[0].repository.fullName,
1047-
scannedRepos[4].repository.fullName,
1048-
],
1051+
expect(parsed).toEqual({
1052+
name: "new-repo-list",
1053+
repositories: [
1054+
scannedRepos[2].repository.fullName,
1055+
scannedRepos[0].repository.fullName,
1056+
scannedRepos[4].repository.fullName,
1057+
],
1058+
});
1059+
});
1060+
1061+
it("should use the search value", async () => {
1062+
await variantAnalysisManager.copyRepoListToClipboard(
1063+
variantAnalysis.id,
1064+
{
1065+
...defaultFilterSortState,
1066+
searchValue: "ban",
1067+
},
1068+
);
1069+
1070+
const text = writeTextStub.mock.calls[0][0];
1071+
1072+
const parsed = JSON.parse(`${text}`);
1073+
1074+
expect(parsed).toEqual({
1075+
name: "new-repo-list",
1076+
repositories: [scannedRepos[4].repository.fullName],
1077+
});
10491078
});
10501079
});
1080+
describe("newQueryRunExperience false", () => {
1081+
it("should be valid JSON when put in object", async () => {
1082+
await variantAnalysisManager.copyRepoListToClipboard(
1083+
variantAnalysis.id,
1084+
);
10511085

1052-
it("should use the search value", async () => {
1053-
await variantAnalysisManager.copyRepoListToClipboard(
1054-
variantAnalysis.id,
1055-
{
1056-
...defaultFilterSortState,
1057-
searchValue: "ban",
1058-
},
1059-
);
1086+
const text = writeTextStub.mock.calls[0][0];
1087+
1088+
const parsed = JSON.parse(`{${text}}`);
1089+
1090+
expect(parsed).toEqual({
1091+
"new-repo-list": [
1092+
scannedRepos[4].repository.fullName,
1093+
scannedRepos[2].repository.fullName,
1094+
scannedRepos[0].repository.fullName,
1095+
],
1096+
});
1097+
});
1098+
1099+
it("should use the sort key", async () => {
1100+
await variantAnalysisManager.copyRepoListToClipboard(
1101+
variantAnalysis.id,
1102+
{
1103+
...defaultFilterSortState,
1104+
sortKey: SortKey.ResultsCount,
1105+
},
1106+
);
1107+
1108+
const text = writeTextStub.mock.calls[0][0];
1109+
1110+
const parsed = JSON.parse(`{${text}}`);
1111+
1112+
expect(parsed).toEqual({
1113+
"new-repo-list": [
1114+
scannedRepos[2].repository.fullName,
1115+
scannedRepos[0].repository.fullName,
1116+
scannedRepos[4].repository.fullName,
1117+
],
1118+
});
1119+
});
1120+
1121+
it("should use the search value", async () => {
1122+
await variantAnalysisManager.copyRepoListToClipboard(
1123+
variantAnalysis.id,
1124+
{
1125+
...defaultFilterSortState,
1126+
searchValue: "ban",
1127+
},
1128+
);
10601129

1061-
const text = writeTextStub.mock.calls[0][0];
1130+
const text = writeTextStub.mock.calls[0][0];
10621131

1063-
const parsed = JSON.parse(`{${text}}`);
1132+
const parsed = JSON.parse(`{${text}}`);
10641133

1065-
expect(parsed).toEqual({
1066-
"new-repo-list": [scannedRepos[4].repository.fullName],
1134+
expect(parsed).toEqual({
1135+
"new-repo-list": [scannedRepos[4].repository.fullName],
1136+
});
10671137
});
10681138
});
10691139
});

0 commit comments

Comments
 (0)