Skip to content

Commit dbe9807

Browse files
committed
Remove codeQL.exportRemoteQueryResults command
1 parent b2ea120 commit dbe9807

File tree

23 files changed

+3
-2319
lines changed

23 files changed

+3
-2319
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ import {
110110
} from "./packaging";
111111
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
112112
import {
113-
exportRemoteQueryResults,
114113
exportSelectedRemoteQueryResults,
115114
exportVariantAnalysisResults,
116115
} from "./remote-queries/export-results";
@@ -1195,15 +1194,6 @@ async function activateWithInstalledDistribution(
11951194
}),
11961195
);
11971196

1198-
ctx.subscriptions.push(
1199-
commandRunner(
1200-
"codeQL.exportRemoteQueryResults",
1201-
async (queryId: string) => {
1202-
await exportRemoteQueryResults(qhm, rqm, queryId, app.credentials);
1203-
},
1204-
),
1205-
);
1206-
12071197
ctx.subscriptions.push(
12081198
commandRunnerWithProgress(
12091199
"codeQL.exportVariantAnalysisResults",

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,10 +1312,7 @@ export class QueryHistoryManager extends DisposableObject {
13121312

13131313
// Remote queries and variant analysis only
13141314
if (finalSingleItem.t === "remote") {
1315-
await commands.executeCommand(
1316-
"codeQL.exportRemoteQueryResults",
1317-
finalSingleItem.queryId,
1318-
);
1315+
// Do nothing. TODO: Remove this case once remote queries are removed.
13191316
} else if (finalSingleItem.t === "variant-analysis") {
13201317
await commands.executeCommand(
13211318
"codeQL.exportVariantAnalysisResults",

extensions/ql-vscode/src/remote-queries/export-results.ts

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { join } from "path";
22
import { ensureDir, writeFile } from "fs-extra";
33

44
import {
5-
commands,
65
CancellationToken,
6+
commands,
77
Uri,
88
ViewColumn,
99
window,
@@ -14,15 +14,11 @@ import { showInformationMessageWithAction } from "../helpers";
1414
import { extLogger } from "../common";
1515
import { QueryHistoryManager } from "../query-history/query-history-manager";
1616
import { createGist } from "./gh-api/gh-api-client";
17-
import { RemoteQueriesManager } from "./remote-queries-manager";
1817
import {
19-
generateMarkdown,
2018
generateVariantAnalysisMarkdown,
2119
MarkdownFile,
2220
RepositorySummary,
2321
} from "./remote-queries-markdown-generation";
24-
import { RemoteQuery } from "./remote-query";
25-
import { AnalysisResults, sumAnalysesResults } from "./shared/analysis-result";
2622
import { pluralize } from "../pure/word";
2723
import { VariantAnalysisManager } from "./variant-analysis-manager";
2824
import { assertNever } from "../pure/helpers-pure";
@@ -52,10 +48,7 @@ export async function exportSelectedRemoteQueryResults(
5248
}
5349

5450
if (queryHistoryItem.t === "remote") {
55-
return commands.executeCommand(
56-
"codeQL.exportRemoteQueryResults",
57-
queryHistoryItem.queryId,
58-
);
51+
// Do nothing. TODO: Remove this branch once we stop supporting remote queries.
5952
} else if (queryHistoryItem.t === "variant-analysis") {
6053
return commands.executeCommand(
6154
"codeQL.exportVariantAnalysisResults",
@@ -66,73 +59,6 @@ export async function exportSelectedRemoteQueryResults(
6659
}
6760
}
6861

69-
/**
70-
* Exports the results of the given remote query.
71-
* The user is prompted to select the export format.
72-
*/
73-
export async function exportRemoteQueryResults(
74-
queryHistoryManager: QueryHistoryManager,
75-
remoteQueriesManager: RemoteQueriesManager,
76-
queryId: string,
77-
credentials: Credentials,
78-
): Promise<void> {
79-
const queryHistoryItem = queryHistoryManager.getRemoteQueryById(queryId);
80-
if (!queryHistoryItem) {
81-
void extLogger.log(`Could not find query with id ${queryId}`);
82-
throw new Error(
83-
"There was an error when trying to retrieve variant analysis information",
84-
);
85-
}
86-
87-
if (!queryHistoryItem.completed) {
88-
throw new Error("Variant analysis results are not yet available.");
89-
}
90-
91-
void extLogger.log(
92-
`Exporting variant analysis results for query: ${queryHistoryItem.queryId}`,
93-
);
94-
const query = queryHistoryItem.remoteQuery;
95-
const analysesResults = remoteQueriesManager.getAnalysesResults(
96-
queryHistoryItem.queryId,
97-
);
98-
99-
const exportFormat = await determineExportFormat();
100-
if (!exportFormat) {
101-
return;
102-
}
103-
104-
const exportDirectory =
105-
await queryHistoryManager.getQueryHistoryItemDirectory(queryHistoryItem);
106-
const exportedResultsDirectory = join(exportDirectory, "exported-results");
107-
108-
await exportRemoteQueryAnalysisResults(
109-
exportedResultsDirectory,
110-
query,
111-
analysesResults,
112-
exportFormat,
113-
credentials,
114-
);
115-
}
116-
117-
export async function exportRemoteQueryAnalysisResults(
118-
exportedResultsPath: string,
119-
query: RemoteQuery,
120-
analysesResults: AnalysisResults[],
121-
exportFormat: "gist" | "local",
122-
credentials: Credentials,
123-
) {
124-
const description = buildGistDescription(query, analysesResults);
125-
const markdownFiles = generateMarkdown(query, analysesResults, exportFormat);
126-
127-
await exportResults(
128-
exportedResultsPath,
129-
description,
130-
markdownFiles,
131-
exportFormat,
132-
credentials,
133-
);
134-
}
135-
13662
const MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS = 2;
13763

13864
/**
@@ -396,22 +322,6 @@ export async function exportToGist(
396322
}
397323
}
398324

399-
/**
400-
* Builds Gist description
401-
* Ex: Empty Block (Go) x results (y repositories)
402-
*/
403-
const buildGistDescription = (
404-
query: RemoteQuery,
405-
analysesResults: AnalysisResults[],
406-
) => {
407-
const resultCount = sumAnalysesResults(analysesResults);
408-
const resultLabel = pluralize(resultCount, "result", "results");
409-
const repositoryLabel = query.repositoryCount
410-
? `(${pluralize(query.repositoryCount, "repository", "repositories")})`
411-
: "";
412-
return `${query.queryName} (${query.language}) ${resultLabel} ${repositoryLabel}`;
413-
};
414-
415325
/**
416326
* Builds Gist description
417327
* Ex: Empty Block (Go) x results (y repositories)

extensions/ql-vscode/src/remote-queries/remote-queries-markdown-generation.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import { tryGetRemoteLocation } from "../pure/bqrs-utils";
33
import { createRemoteFileRef } from "../pure/location-link-utils";
44
import { parseHighlightedLine, shouldHighlightLine } from "../pure/sarif-utils";
55
import { convertNonPrintableChars } from "../text-utils";
6-
import { RemoteQuery } from "./remote-query";
76
import {
87
AnalysisAlert,
98
AnalysisRawResults,
10-
AnalysisResults,
119
CodeSnippet,
1210
FileLink,
13-
getAnalysisResultCount,
1411
HighlightedRegion,
1512
} from "./shared/analysis-result";
1613
import {
@@ -27,54 +24,6 @@ export interface MarkdownFile {
2724
content: string[]; // Each array item is a line of the markdown file.
2825
}
2926

30-
/**
31-
* Generates markdown files with variant analysis results.
32-
*/
33-
export function generateMarkdown(
34-
query: RemoteQuery,
35-
analysesResults: AnalysisResults[],
36-
linkType: MarkdownLinkType,
37-
): MarkdownFile[] {
38-
const resultsFiles: MarkdownFile[] = [];
39-
// Generate summary file with links to individual files
40-
const summaryFile: MarkdownFile = generateMarkdownSummary(query);
41-
for (const analysisResult of analysesResults) {
42-
const resultsCount = getAnalysisResultCount(analysisResult);
43-
if (resultsCount === 0) {
44-
continue;
45-
}
46-
47-
// Append nwo and results count to the summary table
48-
const nwo = analysisResult.nwo;
49-
const fileName = createFileName(nwo);
50-
const link = createRelativeLink(fileName, linkType);
51-
summaryFile.content.push(
52-
`| ${nwo} | [${resultsCount} result(s)](${link}) |`,
53-
);
54-
55-
// Generate individual markdown file for each repository
56-
const resultsFileContent = [`### ${analysisResult.nwo}`, ""];
57-
for (const interpretedResult of analysisResult.interpretedResults) {
58-
const individualResult = generateMarkdownForInterpretedResult(
59-
interpretedResult,
60-
query.language,
61-
);
62-
resultsFileContent.push(...individualResult);
63-
}
64-
if (analysisResult.rawResults) {
65-
const rawResultTable = generateMarkdownForRawResults(
66-
analysisResult.rawResults,
67-
);
68-
resultsFileContent.push(...rawResultTable);
69-
}
70-
resultsFiles.push({
71-
fileName,
72-
content: resultsFileContent,
73-
});
74-
}
75-
return [summaryFile, ...resultsFiles];
76-
}
77-
7827
export interface RepositorySummary {
7928
fileName: string;
8029
repository: RepositoryWithMetadata;
@@ -153,27 +102,6 @@ export async function generateVariantAnalysisMarkdown(
153102
};
154103
}
155104

156-
export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
157-
const lines: string[] = [];
158-
// Title
159-
lines.push(`### Results for "${query.queryName}"`, "");
160-
161-
// Expandable section containing query text
162-
const queryCodeBlock = ["```ql", ...query.queryText.split("\n"), "```"];
163-
lines.push(...buildExpandableMarkdownSection("Query", queryCodeBlock));
164-
165-
// Padding between sections
166-
lines.push("<br />", "");
167-
168-
// Summary table
169-
lines.push("### Summary", "", "| Repository | Results |", "| --- | --- |");
170-
// nwo and result count will be appended to this table
171-
return {
172-
fileName: "_summary",
173-
content: lines,
174-
};
175-
}
176-
177105
export function generateVariantAnalysisMarkdownSummary(
178106
variantAnalysis: VariantAnalysis,
179107
summaries: RepositorySummary[],

extensions/ql-vscode/src/remote-queries/remote-queries-view.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ViewColumn,
55
Uri,
66
workspace,
7-
commands,
87
} from "vscode";
98
import { basename } from "path";
109

@@ -162,10 +161,6 @@ export class RemoteQueriesView extends AbstractWebview<
162161
await this.downloadAllAnalysesResults(msg);
163162
break;
164163
case "remoteQueryExportResults":
165-
await commands.executeCommand(
166-
"codeQL.exportRemoteQueryResults",
167-
msg.queryId,
168-
);
169164
break;
170165
case "telemetry":
171166
telemetryListener?.sendUIInteraction(msg.action);

0 commit comments

Comments
 (0)