Sort Gist files by user-defined sort order
This will sort the files in an exported Gist by the user-defined sort
order. It does so by prefixing the files with `result-{index}-` where
the `index` is the 1-based index of the repository in the sort order.
It will automatically pad the index with leading zeros to ensure that
the files are sorted in the correct order.
Unfortunately, we can't just use `{index}-` because numbers sort before
the `_` character, which is used in the summary filename to place it
first.
There are also some changes in how we determine which repositories to
export since we need to know in advance how many zeroes we need to pad
the index with. There should be no functional changes in which
repositories are actually exported.
This commit is contained in:
@@ -187,6 +187,17 @@ export async function exportVariantAnalysisResults(
|
||||
throw new UserCancellationException("Cancelled");
|
||||
}
|
||||
|
||||
const repositories = filterAndSortRepositoriesWithResults(
|
||||
variantAnalysis.scannedRepos,
|
||||
filterSort,
|
||||
)?.filter(
|
||||
(repo) =>
|
||||
repo.resultCount &&
|
||||
repoStates.find((r) => r.repositoryId === repo.repository.id)
|
||||
?.downloadStatus ===
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
);
|
||||
|
||||
async function* getAnalysesResults(): AsyncGenerator<
|
||||
[VariantAnalysisScannedRepository, VariantAnalysisScannedRepositoryResult]
|
||||
> {
|
||||
@@ -194,38 +205,11 @@ export async function exportVariantAnalysisResults(
|
||||
return;
|
||||
}
|
||||
|
||||
const repositories = filterAndSortRepositoriesWithResults(
|
||||
variantAnalysis.scannedRepos,
|
||||
filterSort,
|
||||
);
|
||||
if (!repositories) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const repo of repositories) {
|
||||
const repoState = repoStates.find(
|
||||
(r) => r.repositoryId === repo.repository.id,
|
||||
);
|
||||
|
||||
// Do not export if it has not yet completed or the download has not yet succeeded.
|
||||
if (
|
||||
repoState?.downloadStatus !==
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (repo.resultCount == 0) {
|
||||
yield [
|
||||
repo,
|
||||
{
|
||||
variantAnalysisId: variantAnalysis.id,
|
||||
repositoryId: repo.repository.id,
|
||||
},
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = await variantAnalysisManager.loadResults(
|
||||
variantAnalysis.id,
|
||||
repo.repository.fullName,
|
||||
@@ -259,6 +243,7 @@ export async function exportVariantAnalysisResults(
|
||||
exportedResultsDirectory,
|
||||
variantAnalysis,
|
||||
getAnalysesResults(),
|
||||
repositories?.length ?? 0,
|
||||
exportFormat,
|
||||
progress,
|
||||
token,
|
||||
@@ -272,6 +257,7 @@ export async function exportVariantAnalysisAnalysisResults(
|
||||
analysesResults: AsyncIterable<
|
||||
[VariantAnalysisScannedRepository, VariantAnalysisScannedRepositoryResult]
|
||||
>,
|
||||
expectedAnalysesResultsCount: number,
|
||||
exportFormat: "gist" | "local",
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken,
|
||||
@@ -289,6 +275,7 @@ export async function exportVariantAnalysisAnalysisResults(
|
||||
const { markdownFiles, summaries } = await generateVariantAnalysisMarkdown(
|
||||
variantAnalysis,
|
||||
analysesResults,
|
||||
expectedAnalysesResultsCount,
|
||||
exportFormat,
|
||||
);
|
||||
const description = buildVariantAnalysisGistDescription(
|
||||
|
||||
@@ -94,18 +94,25 @@ export async function generateVariantAnalysisMarkdown(
|
||||
results: AsyncIterable<
|
||||
[VariantAnalysisScannedRepository, VariantAnalysisScannedRepositoryResult]
|
||||
>,
|
||||
expectedResultsCount: number,
|
||||
linkType: MarkdownLinkType,
|
||||
): Promise<VariantAnalysisMarkdown> {
|
||||
const resultsFiles: MarkdownFile[] = [];
|
||||
const summaries: RepositorySummary[] = [];
|
||||
|
||||
for await (const [scannedRepo, result] of results) {
|
||||
if (!scannedRepo.resultCount || scannedRepo.resultCount === 0) {
|
||||
if (!scannedRepo.resultCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Append nwo and results count to the summary table
|
||||
const fullName = scannedRepo.repository.fullName;
|
||||
const fileName = createFileName(fullName);
|
||||
const fileName = createVariantAnalysisFileName(
|
||||
fullName,
|
||||
resultsFiles.length,
|
||||
expectedResultsCount,
|
||||
linkType,
|
||||
);
|
||||
summaries.push({
|
||||
fileName,
|
||||
repository: scannedRepo.repository,
|
||||
@@ -482,6 +489,32 @@ function createFileName(nwo: string) {
|
||||
return `${owner}-${repo}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the name of the markdown file for a given repository nwo.
|
||||
* This name doesn't include the file extension.
|
||||
*/
|
||||
function createVariantAnalysisFileName(
|
||||
fullName: string,
|
||||
index: number,
|
||||
expectedResultsCount: number,
|
||||
linkType: MarkdownLinkType,
|
||||
) {
|
||||
const baseName = createFileName(fullName);
|
||||
if (linkType === "gist") {
|
||||
const requiredNumberOfDecimals = Math.ceil(
|
||||
Math.log10(expectedResultsCount),
|
||||
);
|
||||
|
||||
const prefix = (index + 1)
|
||||
.toString()
|
||||
.padStart(requiredNumberOfDecimals, "0");
|
||||
|
||||
return `result-${prefix}-${baseName}`;
|
||||
}
|
||||
|
||||
return baseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape characters that could be interpreted as HTML instead of raw code.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user