Support new DB config format in "copy repo list" function (#1927)

This commit is contained in:
Shati Patel
2023-01-05 10:56:55 +00:00
committed by GitHub
parent afc6ce5211
commit 4dba169412
2 changed files with 132 additions and 48 deletions

View File

@@ -60,6 +60,7 @@ import {
} from "../pure/variant-analysis-filter-sort";
import { URLSearchParams } from "url";
import { DbManager } from "../databases/db-manager";
import { isNewQueryRunExperienceEnabled } from "../config";
export class VariantAnalysisManager
extends DisposableObject
@@ -605,12 +606,25 @@ export class VariantAnalysisManager
return;
}
const text = [
'"new-repo-list": [',
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
` "${fullNames[fullNames.length - 1]}"`,
"]",
];
let text: string[];
if (isNewQueryRunExperienceEnabled()) {
text = [
"{",
` "name": "new-repo-list",`,
` "repositories": [`,
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
` "${fullNames[fullNames.length - 1]}"`,
` ]`,
"}",
];
} else {
text = [
'"new-repo-list": [',
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
` "${fullNames[fullNames.length - 1]}"`,
"]",
];
}
await env.clipboard.writeText(text.join(EOL));
}

View File

@@ -1009,61 +1009,131 @@ describe("Variant Analysis Manager", () => {
expect(writeTextStub).toBeCalledTimes(1);
});
it("should be valid JSON when put in object", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
);
describe("newQueryRunExperience true", () => {
beforeEach(() => {
jest
.spyOn(config, "isNewQueryRunExperienceEnabled")
.mockReturnValue(true);
});
const text = writeTextStub.mock.calls[0][0];
it("should be valid JSON when put in object", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
);
const parsed = JSON.parse(`{${text}}`);
const text = writeTextStub.mock.calls[0][0];
expect(parsed).toEqual({
"new-repo-list": [
scannedRepos[4].repository.fullName,
scannedRepos[2].repository.fullName,
scannedRepos[0].repository.fullName,
],
const parsed = JSON.parse(`${text}`);
expect(parsed).toEqual({
name: "new-repo-list",
repositories: [
scannedRepos[4].repository.fullName,
scannedRepos[2].repository.fullName,
scannedRepos[0].repository.fullName,
],
});
});
it("should use the sort key", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
{
...defaultFilterSortState,
sortKey: SortKey.ResultsCount,
},
);
const text = writeTextStub.mock.calls[0][0];
const parsed = JSON.parse(`${text}`);
expect(parsed).toEqual({
name: "new-repo-list",
repositories: [
scannedRepos[2].repository.fullName,
scannedRepos[0].repository.fullName,
scannedRepos[4].repository.fullName,
],
});
});
it("should use the search value", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
{
...defaultFilterSortState,
searchValue: "ban",
},
);
const text = writeTextStub.mock.calls[0][0];
const parsed = JSON.parse(`${text}`);
expect(parsed).toEqual({
name: "new-repo-list",
repositories: [scannedRepos[4].repository.fullName],
});
});
});
describe("newQueryRunExperience false", () => {
it("should be valid JSON when put in object", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
);
it("should use the sort key", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
{
...defaultFilterSortState,
sortKey: SortKey.ResultsCount,
},
);
const text = writeTextStub.mock.calls[0][0];
const text = writeTextStub.mock.calls[0][0];
const parsed = JSON.parse(`{${text}}`);
const parsed = JSON.parse(`{${text}}`);
expect(parsed).toEqual({
"new-repo-list": [
scannedRepos[2].repository.fullName,
scannedRepos[0].repository.fullName,
scannedRepos[4].repository.fullName,
],
expect(parsed).toEqual({
"new-repo-list": [
scannedRepos[4].repository.fullName,
scannedRepos[2].repository.fullName,
scannedRepos[0].repository.fullName,
],
});
});
});
it("should use the search value", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
{
...defaultFilterSortState,
searchValue: "ban",
},
);
it("should use the sort key", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
{
...defaultFilterSortState,
sortKey: SortKey.ResultsCount,
},
);
const text = writeTextStub.mock.calls[0][0];
const text = writeTextStub.mock.calls[0][0];
const parsed = JSON.parse(`{${text}}`);
const parsed = JSON.parse(`{${text}}`);
expect(parsed).toEqual({
"new-repo-list": [scannedRepos[4].repository.fullName],
expect(parsed).toEqual({
"new-repo-list": [
scannedRepos[2].repository.fullName,
scannedRepos[0].repository.fullName,
scannedRepos[4].repository.fullName,
],
});
});
it("should use the search value", async () => {
await variantAnalysisManager.copyRepoListToClipboard(
variantAnalysis.id,
{
...defaultFilterSortState,
searchValue: "ban",
},
);
const text = writeTextStub.mock.calls[0][0];
const parsed = JSON.parse(`{${text}}`);
expect(parsed).toEqual({
"new-repo-list": [scannedRepos[4].repository.fullName],
});
});
});
});