Skip to content

Commit a97c5fe

Browse files
authored
MRVA: Support both local and gist links when generating markdown
1 parent 9b6eddd commit a97c5fe

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import { convertNonPrintableChars } from '../text-utils';
66
import { RemoteQuery } from './remote-query';
77
import { AnalysisAlert, AnalysisRawResults, AnalysisResults, CodeSnippet, FileLink, getAnalysisResultCount, HighlightedRegion } from './shared/analysis-result';
88

9+
export type MarkdownLinkType = 'local' | 'gist';
10+
911
// Each array item is a line of the markdown file.
1012
export type MarkdownFile = string[];
1113

1214
/**
1315
* Generates markdown files with variant analysis results.
1416
*/
15-
export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisResults[]): MarkdownFile[] {
17+
export function generateMarkdown(
18+
query: RemoteQuery,
19+
analysesResults: AnalysisResults[],
20+
linkType: MarkdownLinkType
21+
): MarkdownFile[] {
1622
const files: MarkdownFile[] = [];
1723
// Generate summary file with links to individual files
1824
const summaryLines: MarkdownFile = generateMarkdownSummary(query);
@@ -24,7 +30,7 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
2430

2531
// Append nwo and results count to the summary table
2632
const nwo = analysisResult.nwo;
27-
const link = createGistRelativeLink(nwo);
33+
const link = createRelativeLink(nwo, linkType);
2834
summaryLines.push(`| ${nwo} | [${resultsCount} result(s)](${link}) |`);
2935

3036
// Generate individual markdown file for each repository
@@ -290,13 +296,18 @@ function buildExpandableMarkdownSection(title: string, contents: MarkdownFile):
290296
return expandableLines;
291297
}
292298

293-
/**
294-
* Creates anchor link to a file in the gist. This is of the form:
295-
* '#file-<name>-<file-extension>'
296-
*
297-
* TODO: Make sure these names align with the actual file names once we upload them to a gist.
298-
*/
299-
function createGistRelativeLink(nwo: string): string {
299+
function createRelativeLink(nwo: string, linkType: MarkdownLinkType): string {
300300
const [owner, repo] = nwo.split('/');
301-
return `#file-${owner}-${repo}-md`;
301+
302+
switch (linkType) {
303+
case 'local':
304+
return `./${owner}-${repo}.md`;
305+
306+
case 'gist':
307+
// Creates anchor link to a file in the gist. This is of the form:
308+
// '#file-<name>-<file-extension>'
309+
//
310+
// TODO: Make sure these names align with the actual file names once we upload them to a gist.
311+
return `#file-${owner}-${repo}-md`;
312+
}
302313
}

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/markdown-generation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('markdown generation', async function() {
1313
const analysesResults = JSON.parse(
1414
await fs.readFile(path.join(__dirname, 'data/interpreted-results/path-problem/analyses-results.json'), 'utf8')
1515
);
16-
const markdownFiles = generateMarkdown(pathProblemQuery, analysesResults);
16+
const markdownFiles = generateMarkdown(pathProblemQuery, analysesResults, 'gist');
1717

1818
// Check that query has results for two repositories, plus a summary file
1919
expect(markdownFiles.length).to.equal(3);
@@ -42,7 +42,7 @@ describe('markdown generation', async function() {
4242
const analysesResults = JSON.parse(
4343
await fs.readFile(path.join(__dirname, 'data/interpreted-results/problem/analyses-results.json'), 'utf8')
4444
);
45-
const markdownFiles = generateMarkdown(problemQuery, analysesResults);
45+
const markdownFiles = generateMarkdown(problemQuery, analysesResults, 'gist');
4646

4747
// Check that query has results for two repositories, plus a summary file
4848
expect(markdownFiles.length).to.equal(3);
@@ -71,7 +71,7 @@ describe('markdown generation', async function() {
7171
await fs.readFile(path.join(__dirname, 'data/raw-results/analyses-results.json'), 'utf8')
7272
);
7373

74-
const markdownFiles = generateMarkdown(query, analysesResults);
74+
const markdownFiles = generateMarkdown(query, analysesResults, 'gist');
7575

7676
// Check that query has results for two repositories, plus a summary file
7777
expect(markdownFiles.length).to.equal(3);

0 commit comments

Comments
 (0)