MRVA: Support both local and gist links when generating markdown
This commit is contained in:
@@ -6,13 +6,19 @@ import { convertNonPrintableChars } from '../text-utils';
|
||||
import { RemoteQuery } from './remote-query';
|
||||
import { AnalysisAlert, AnalysisRawResults, AnalysisResults, CodeSnippet, FileLink, getAnalysisResultCount, HighlightedRegion } from './shared/analysis-result';
|
||||
|
||||
export type MarkdownLinkType = 'local' | 'gist';
|
||||
|
||||
// Each array item is a line of the markdown file.
|
||||
export type MarkdownFile = string[];
|
||||
|
||||
/**
|
||||
* Generates markdown files with variant analysis results.
|
||||
*/
|
||||
export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisResults[]): MarkdownFile[] {
|
||||
export function generateMarkdown(
|
||||
query: RemoteQuery,
|
||||
analysesResults: AnalysisResults[],
|
||||
linkType: MarkdownLinkType
|
||||
): MarkdownFile[] {
|
||||
const files: MarkdownFile[] = [];
|
||||
// Generate summary file with links to individual files
|
||||
const summaryLines: MarkdownFile = generateMarkdownSummary(query);
|
||||
@@ -24,7 +30,7 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
|
||||
|
||||
// Append nwo and results count to the summary table
|
||||
const nwo = analysisResult.nwo;
|
||||
const link = createGistRelativeLink(nwo);
|
||||
const link = createRelativeLink(nwo, linkType);
|
||||
summaryLines.push(`| ${nwo} | [${resultsCount} result(s)](${link}) |`);
|
||||
|
||||
// Generate individual markdown file for each repository
|
||||
@@ -290,13 +296,18 @@ function buildExpandableMarkdownSection(title: string, contents: MarkdownFile):
|
||||
return expandableLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates anchor link to a file in the gist. This is of the form:
|
||||
* '#file-<name>-<file-extension>'
|
||||
*
|
||||
* TODO: Make sure these names align with the actual file names once we upload them to a gist.
|
||||
*/
|
||||
function createGistRelativeLink(nwo: string): string {
|
||||
function createRelativeLink(nwo: string, linkType: MarkdownLinkType): string {
|
||||
const [owner, repo] = nwo.split('/');
|
||||
return `#file-${owner}-${repo}-md`;
|
||||
|
||||
switch (linkType) {
|
||||
case 'local':
|
||||
return `./${owner}-${repo}.md`;
|
||||
|
||||
case 'gist':
|
||||
// Creates anchor link to a file in the gist. This is of the form:
|
||||
// '#file-<name>-<file-extension>'
|
||||
//
|
||||
// TODO: Make sure these names align with the actual file names once we upload them to a gist.
|
||||
return `#file-${owner}-${repo}-md`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ describe('markdown generation', async function() {
|
||||
const analysesResults = JSON.parse(
|
||||
await fs.readFile(path.join(__dirname, 'data/interpreted-results/path-problem/analyses-results.json'), 'utf8')
|
||||
);
|
||||
const markdownFiles = generateMarkdown(pathProblemQuery, analysesResults);
|
||||
const markdownFiles = generateMarkdown(pathProblemQuery, analysesResults, 'gist');
|
||||
|
||||
// Check that query has results for two repositories, plus a summary file
|
||||
expect(markdownFiles.length).to.equal(3);
|
||||
@@ -42,7 +42,7 @@ describe('markdown generation', async function() {
|
||||
const analysesResults = JSON.parse(
|
||||
await fs.readFile(path.join(__dirname, 'data/interpreted-results/problem/analyses-results.json'), 'utf8')
|
||||
);
|
||||
const markdownFiles = generateMarkdown(problemQuery, analysesResults);
|
||||
const markdownFiles = generateMarkdown(problemQuery, analysesResults, 'gist');
|
||||
|
||||
// Check that query has results for two repositories, plus a summary file
|
||||
expect(markdownFiles.length).to.equal(3);
|
||||
@@ -71,7 +71,7 @@ describe('markdown generation', async function() {
|
||||
await fs.readFile(path.join(__dirname, 'data/raw-results/analyses-results.json'), 'utf8')
|
||||
);
|
||||
|
||||
const markdownFiles = generateMarkdown(query, analysesResults);
|
||||
const markdownFiles = generateMarkdown(query, analysesResults, 'gist');
|
||||
|
||||
// Check that query has results for two repositories, plus a summary file
|
||||
expect(markdownFiles.length).to.equal(3);
|
||||
|
||||
Reference in New Issue
Block a user