Fix Gist title in result export
The Gist title in the result export didn't take into account the actual number of exported repositories, it only used the scanned, unfiltered, repositories in the variant analysis. This switches it to use the actual exported repositories for determining the result and repository counts. This is somewhat more complicated than we'd expect it to be since the results are being read in async, so we need to switch the order of operations and store some additional information for being able to compute this information. However, this also makes the code somewhat easier to understand since the summary file is now being created in only 1 location, rather than being split between a method and a for-loop.
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
generateMarkdown,
|
||||
generateVariantAnalysisMarkdown,
|
||||
MarkdownFile,
|
||||
RepositorySummary,
|
||||
} from "./remote-queries-markdown-generation";
|
||||
import { RemoteQuery } from "./remote-query";
|
||||
import { AnalysisResults, sumAnalysesResults } from "./shared/analysis-result";
|
||||
@@ -235,11 +236,14 @@ export async function exportVariantAnalysisAnalysisResults(
|
||||
>,
|
||||
exportFormat: "gist" | "local",
|
||||
) {
|
||||
const description = buildVariantAnalysisGistDescription(variantAnalysis);
|
||||
const markdownFiles = await generateVariantAnalysisMarkdown(
|
||||
const { markdownFiles, summaries } = await generateVariantAnalysisMarkdown(
|
||||
variantAnalysis,
|
||||
analysesResults,
|
||||
"gist",
|
||||
exportFormat,
|
||||
);
|
||||
const description = buildVariantAnalysisGistDescription(
|
||||
variantAnalysis,
|
||||
summaries,
|
||||
);
|
||||
|
||||
await exportResults(
|
||||
@@ -345,20 +349,16 @@ const buildGistDescription = (
|
||||
*/
|
||||
const buildVariantAnalysisGistDescription = (
|
||||
variantAnalysis: VariantAnalysis,
|
||||
summaries: RepositorySummary[],
|
||||
) => {
|
||||
const resultCount =
|
||||
variantAnalysis.scannedRepos?.reduce(
|
||||
(acc, item) => acc + (item.resultCount ?? 0),
|
||||
0,
|
||||
) ?? 0;
|
||||
const resultCount = summaries.reduce(
|
||||
(acc, summary) => acc + (summary.resultCount ?? 0),
|
||||
0,
|
||||
);
|
||||
const resultLabel = pluralize(resultCount, "result", "results");
|
||||
|
||||
const repositoryLabel = variantAnalysis.scannedRepos?.length
|
||||
? `(${pluralize(
|
||||
variantAnalysis.scannedRepos.length,
|
||||
"repository",
|
||||
"repositories",
|
||||
)})`
|
||||
const repositoryLabel = summaries.length
|
||||
? `(${pluralize(summaries.length, "repository", "repositories")})`
|
||||
: "";
|
||||
return `${variantAnalysis.query.name} (${variantAnalysis.query.language}) ${resultLabel} ${repositoryLabel}`;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
VariantAnalysisScannedRepository,
|
||||
VariantAnalysisScannedRepositoryResult,
|
||||
} from "./shared/variant-analysis";
|
||||
import { RepositoryWithMetadata } from "./shared/repository";
|
||||
|
||||
export type MarkdownLinkType = "local" | "gist";
|
||||
|
||||
@@ -74,6 +75,17 @@ export function generateMarkdown(
|
||||
return [summaryFile, ...resultsFiles];
|
||||
}
|
||||
|
||||
export interface RepositorySummary {
|
||||
fileName: string;
|
||||
repository: RepositoryWithMetadata;
|
||||
resultCount: number;
|
||||
}
|
||||
|
||||
export interface VariantAnalysisMarkdown {
|
||||
markdownFiles: MarkdownFile[];
|
||||
summaries: RepositorySummary[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates markdown files with variant analysis results.
|
||||
*/
|
||||
@@ -83,23 +95,22 @@ export async function generateVariantAnalysisMarkdown(
|
||||
[VariantAnalysisScannedRepository, VariantAnalysisScannedRepositoryResult]
|
||||
>,
|
||||
linkType: MarkdownLinkType,
|
||||
): Promise<MarkdownFile[]> {
|
||||
): Promise<VariantAnalysisMarkdown> {
|
||||
const resultsFiles: MarkdownFile[] = [];
|
||||
// Generate summary file with links to individual files
|
||||
const summaryFile: MarkdownFile =
|
||||
generateVariantAnalysisMarkdownSummary(variantAnalysis);
|
||||
const summaries: RepositorySummary[] = [];
|
||||
for await (const [scannedRepo, result] of results) {
|
||||
if (scannedRepo.resultCount === 0) {
|
||||
if (!scannedRepo.resultCount || scannedRepo.resultCount === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Append nwo and results count to the summary table
|
||||
const fullName = scannedRepo.repository.fullName;
|
||||
const fileName = createFileName(fullName);
|
||||
const link = createRelativeLink(fileName, linkType);
|
||||
summaryFile.content.push(
|
||||
`| ${fullName} | [${scannedRepo.resultCount} result(s)](${link}) |`,
|
||||
);
|
||||
summaries.push({
|
||||
fileName,
|
||||
repository: scannedRepo.repository,
|
||||
resultCount: scannedRepo.resultCount,
|
||||
});
|
||||
|
||||
// Generate individual markdown file for each repository
|
||||
const resultsFileContent = [`### ${scannedRepo.repository.fullName}`, ""];
|
||||
@@ -121,7 +132,18 @@ export async function generateVariantAnalysisMarkdown(
|
||||
content: resultsFileContent,
|
||||
});
|
||||
}
|
||||
return [summaryFile, ...resultsFiles];
|
||||
|
||||
// Generate summary file with links to individual files
|
||||
const summaryFile: MarkdownFile = generateVariantAnalysisMarkdownSummary(
|
||||
variantAnalysis,
|
||||
summaries,
|
||||
linkType,
|
||||
);
|
||||
|
||||
return {
|
||||
markdownFiles: [summaryFile, ...resultsFiles],
|
||||
summaries,
|
||||
};
|
||||
}
|
||||
|
||||
export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
|
||||
@@ -147,6 +169,8 @@ export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
|
||||
|
||||
export function generateVariantAnalysisMarkdownSummary(
|
||||
variantAnalysis: VariantAnalysis,
|
||||
summaries: RepositorySummary[],
|
||||
linkType: MarkdownLinkType,
|
||||
): MarkdownFile {
|
||||
const lines: string[] = [];
|
||||
// Title
|
||||
@@ -165,7 +189,14 @@ export function generateVariantAnalysisMarkdownSummary(
|
||||
|
||||
// Summary table
|
||||
lines.push("### Summary", "", "| Repository | Results |", "| --- | --- |");
|
||||
// nwo and result count will be appended to this table
|
||||
|
||||
for (const summary of summaries) {
|
||||
// Append nwo and results count to the summary table
|
||||
const fullName = summary.repository.fullName;
|
||||
const link = createRelativeLink(summary.fileName, linkType);
|
||||
lines.push(`| ${fullName} | [${summary.resultCount} result(s)](${link}) |`);
|
||||
}
|
||||
|
||||
return {
|
||||
fileName: "_summary",
|
||||
content: lines,
|
||||
|
||||
Reference in New Issue
Block a user