Formatting fixes and code tidy-up
This commit is contained in:
@@ -19,9 +19,10 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
|
||||
}
|
||||
|
||||
// Append nwo and results count to the summary table
|
||||
summaryLines.push(
|
||||
`| ${analysisResult.nwo} | [${analysisResult.interpretedResults.length} result(s)](${createGistRelativeLink(analysisResult.nwo)}) |`
|
||||
);
|
||||
const nwo = analysisResult.nwo;
|
||||
const resultsCount = analysisResult.interpretedResults.length;
|
||||
const link = createGistRelativeLink(nwo);
|
||||
summaryLines.push(`| ${nwo} | [${resultsCount} result(s)](${link}) |`);
|
||||
|
||||
// Generate individual markdown file for each repository
|
||||
const lines = [
|
||||
@@ -34,15 +35,16 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
|
||||
}
|
||||
files.push(lines);
|
||||
}
|
||||
files.push(summaryLines);
|
||||
return files;
|
||||
return [summaryLines, ...files];
|
||||
}
|
||||
|
||||
export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
|
||||
const lines: MarkdownFile = [];
|
||||
// Title
|
||||
lines.push(`## Results for "${query.queryName}"`);
|
||||
lines.push('');
|
||||
lines.push(
|
||||
`### Results for "${query.queryName}"`,
|
||||
''
|
||||
);
|
||||
|
||||
// Expandable section containing query text
|
||||
const queryCodeBlock = [
|
||||
@@ -54,12 +56,16 @@ export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
|
||||
...buildExpandableMarkdownSection('Query', queryCodeBlock)
|
||||
);
|
||||
|
||||
// Padding between sections
|
||||
lines.push(
|
||||
'<br />',
|
||||
'',
|
||||
);
|
||||
|
||||
// Summary table
|
||||
lines.push(
|
||||
'### Summary',
|
||||
''
|
||||
);
|
||||
lines.push(
|
||||
'',
|
||||
'| Repository | Results |',
|
||||
'| --- | --- |',
|
||||
);
|
||||
@@ -151,9 +157,7 @@ function buildExpandableMarkdownSection(title: string, contents: MarkdownFile):
|
||||
'<details>',
|
||||
`<summary>${title}</summary>`,
|
||||
'',
|
||||
);
|
||||
expandableLines.push(...contents);
|
||||
expandableLines.push(
|
||||
...contents,
|
||||
'',
|
||||
'</details>',
|
||||
''
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
## Results for "Shell command built from environment values"
|
||||
### Results for "Shell command built from environment values"
|
||||
|
||||
<details>
|
||||
<summary>Query</summary>
|
||||
@@ -39,6 +39,8 @@ select highlight, source, sink, "This shell command depends on an uncontrolled $
|
||||
|
||||
</details>
|
||||
|
||||
<br />
|
||||
|
||||
### Summary
|
||||
|
||||
| Repository | Results |
|
||||
|
||||
@@ -17,18 +17,18 @@ describe('markdown generation', async function() {
|
||||
// Check that query has results for two repositories, plus a summary file
|
||||
expect(markdownFiles.length).to.equal(3);
|
||||
|
||||
const markdownFile1 = markdownFiles[0]; // results for github/codeql repo
|
||||
const markdownFile2 = markdownFiles[1]; // results for meteor/meteor repo
|
||||
const markdownFile3 = markdownFiles[2]; // summary file
|
||||
const markdownFile0 = markdownFiles[0]; // summary file
|
||||
const markdownFile1 = markdownFiles[1]; // results for github/codeql repo
|
||||
const markdownFile2 = markdownFiles[2]; // results for meteor/meteor repo
|
||||
|
||||
const expectedSummaryFile = await readTestOutputFile('data/summary.md');
|
||||
const expectedTestOutput1 = await readTestOutputFile('data/results-repo1.md');
|
||||
const expectedTestOutput2 = await readTestOutputFile('data/results-repo2.md');
|
||||
const expectedSummaryFile = await readTestOutputFile('data/summary.md');
|
||||
|
||||
// Check that markdown output is correct, after making line endings consistent
|
||||
expect(markdownFile0.join('\n')).to.equal(expectedSummaryFile);
|
||||
expect(markdownFile1.join('\n')).to.equal(expectedTestOutput1);
|
||||
expect(markdownFile2.join('\n')).to.equal(expectedTestOutput2);
|
||||
expect(markdownFile3.join('\n')).to.equal(expectedSummaryFile);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user