Skip to content

Commit 55ffdf7

Browse files
Merge pull request #1431 from github/shati-elena/rename-gist
Add useful information to MRVA gist titles
2 parents f992679 + cc907d2 commit 55ffdf7

File tree

7 files changed

+566
-19
lines changed

7 files changed

+566
-19
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createGist } from './gh-actions-api-client';
1111
import { RemoteQueriesManager } from './remote-queries-manager';
1212
import { generateMarkdown } from './remote-queries-markdown-generation';
1313
import { RemoteQuery } from './remote-query';
14-
import { AnalysisResults } from './shared/analysis-result';
14+
import { AnalysisResults, sumAnalysesResults } from './shared/analysis-result';
1515

1616
/**
1717
* Exports the results of the currently-selected remote query.
@@ -74,13 +74,13 @@ async function determineExportFormat(
7474
/**
7575
* Converts the results of a remote query to markdown and uploads the files as a secret gist.
7676
*/
77-
async function exportResultsToGist(
77+
export async function exportResultsToGist(
7878
ctx: ExtensionContext,
7979
query: RemoteQuery,
8080
analysesResults: AnalysisResults[]
8181
): Promise<void> {
8282
const credentials = await Credentials.initialize(ctx);
83-
const description = 'CodeQL Variant Analysis Results';
83+
const description = buildGistDescription(query, analysesResults);
8484
const markdownFiles = generateMarkdown(query, analysesResults, 'gist');
8585
// Convert markdownFiles to the appropriate format for uploading to gist
8686
const gistFiles = markdownFiles.reduce((acc, cur) => {
@@ -100,6 +100,17 @@ async function exportResultsToGist(
100100
}
101101
}
102102

103+
/**
104+
* Builds Gist description
105+
* Ex: Empty Block (Go) x results (y repositories)
106+
*/
107+
const buildGistDescription = (query: RemoteQuery, analysesResults: AnalysisResults[]) => {
108+
const resultCount = sumAnalysesResults(analysesResults);
109+
const repositoryLabel = `${query.numRepositoriesQueried} ${query.numRepositoriesQueried === 1 ? 'repository' : 'repositories'}`;
110+
const repositoryCount = query.numRepositoriesQueried ? repositoryLabel : '';
111+
return `${query.queryName} (${query.language}) ${resultCount} results (${repositoryCount})`;
112+
};
113+
103114
/**
104115
* Converts the results of a remote query to markdown and saves the files locally
105116
* in the query directory (where query results and metadata are also saved).

extensions/ql-vscode/src/remote-queries/shared/analysis-result.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ export const getAnalysisResultCount = (analysisResults: AnalysisResults): number
9090
const rawResultCount = analysisResults.rawResults?.resultSet.rows.length || 0;
9191
return analysisResults.interpretedResults.length + rawResultCount;
9292
};
93+
94+
/**
95+
* Returns the total number of results for an analysis by adding all individual repo results.
96+
*/
97+
export const sumAnalysesResults = (analysesResults: AnalysisResults[]) =>
98+
analysesResults.reduce((acc, curr) => acc + getAnalysisResultCount(curr), 0);

0 commit comments

Comments
 (0)