Generate markdown for raw result tables

This commit is contained in:
shati-patel
2022-04-28 16:12:11 +01:00
committed by Shati Patel
parent 7d0d11f526
commit 7d3b015e20
3 changed files with 82 additions and 2 deletions

View File

@@ -1,7 +1,10 @@
import { CellValue } from '../pure/bqrs-cli-types';
import { tryGetRemoteLocation } from '../pure/bqrs-utils';
import { createRemoteFileRef } from '../pure/location-link-utils'; import { createRemoteFileRef } from '../pure/location-link-utils';
import { parseHighlightedLine, shouldHighlightLine } from '../pure/sarif-utils'; import { parseHighlightedLine, shouldHighlightLine } from '../pure/sarif-utils';
import { convertNonPrintableChars } from '../text-utils';
import { RemoteQuery } from './remote-query'; import { RemoteQuery } from './remote-query';
import { AnalysisAlert, AnalysisResults, CodeSnippet, FileLink, getAnalysisResultCount, HighlightedRegion } from './shared/analysis-result'; import { AnalysisAlert, AnalysisRawResults, AnalysisResults, CodeSnippet, FileLink, getAnalysisResultCount, HighlightedRegion } from './shared/analysis-result';
// Each array item is a line of the markdown file. // Each array item is a line of the markdown file.
export type MarkdownFile = string[]; export type MarkdownFile = string[];
@@ -34,7 +37,8 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
lines.push(...individualResult); lines.push(...individualResult);
} }
if (analysisResult.rawResults) { if (analysisResult.rawResults) {
// TODO: Generate markdown table for raw results const rawResultTable = generateMarkdownForRawResults(analysisResult.rawResults);
lines.push(...rawResultTable);
} }
files.push(lines); files.push(lines);
} }
@@ -198,6 +202,52 @@ function generateMarkdownForPathResults(
return buildExpandableMarkdownSection('Show paths', pathLines); return buildExpandableMarkdownSection('Show paths', pathLines);
} }
function generateMarkdownForRawResults(
analysisRawResults: AnalysisRawResults
): MarkdownFile {
const tableRows: MarkdownFile = [];
const columnCount = analysisRawResults.schema.columns.length;
// Table headers are the column names if they exist, and empty otherwise
const headers = analysisRawResults.schema.columns.map(
(column) => column.name || ''
);
const tableHeader = `| ${headers.join(' | ')} |`;
tableRows.push(tableHeader);
tableRows.push('|' + ' --- |'.repeat(columnCount));
for (const row of analysisRawResults.resultSet.rows) {
const cells = row.map((cell) =>
generateMarkdownForRawTableCell(cell, analysisRawResults.fileLinkPrefix)
);
tableRows.push(`| ${cells.join(' | ')} |`);
}
return tableRows;
}
function generateMarkdownForRawTableCell(
value: CellValue,
fileLinkPrefix: string
) {
let cellValue: string;
switch (typeof value) {
case 'string':
case 'number':
case 'boolean':
cellValue = `\`${convertNonPrintableChars(value.toString())}\``;
break;
case 'object':
{
const url = tryGetRemoteLocation(value.url, fileLinkPrefix);
cellValue = `[\`${convertNonPrintableChars(value.label)}\`](${url})`;
}
break;
}
// `|` characters break the table, so we need to escape them
return cellValue.replace('|', '\\|');
}
/** /**
* Creates a markdown link to a remote file. * Creates a markdown link to a remote file.
* If the "link text" is not provided, we use the file path. * If the "link text" is not provided, we use the file path.

View File

@@ -1 +1,26 @@
### github/codeql ### github/codeql
| c | |
| --- | --- |
| [`functio ... ght);\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/src/Expressions/examples/CompareIdenticalValues.js#L8-L13) | `6` |
| [`functio ... i-1);\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/src/LanguageFeatures/examples/ArgumentsCallerCallee.js#L1-L5) | `5` |
| [`functio ... i-1);\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/src/LanguageFeatures/examples/ArgumentsCallerCalleeGood.js#L1-L5) | `5` |
| [`functio ... n -1;\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/src/Statements/examples/UselessComparisonTest.js#L1-L12) | `12` |
| [`functio ... false\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/constants.js#L1-L8) | `8` |
| [`functio ... \n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/loop.js#L1-L12) | `12` |
| [`functio ... e\n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/loop.js#L14-L22) | `9` |
| [`functio ... K\n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/loop.js#L24-L40) | `17` |
| [`functio ... e\n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/plus.js#L1-L17) | `17` |
| [`functio ... alse \n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/plus.js#L19-L28) | `10` |
| [`functio ... true\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/plus.js#L30-L33) | `4` |
| [`functio ... K\n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/tst.js#L1-L15) | `15` |
| [`functio ... e\n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/tst.js#L17-L31) | `15` |
| [`functio ... false\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/tst.js#L33-L41) | `9` |
| [`functio ... e\n }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/library-tests/RangeAnalysis/tst.js#L43-L52) | `10` |
| [`functio ... ght);\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/Expressions/CompareIdenticalValues/tst.js#L8-L13) | `6` |
| [`functio ... i-1);\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/LanguageFeatures/ArgumentsCallerCallee/tst.js#L1-L5) | `5` |
| [`functio ... }\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/Security/CWE-834/LoopBoundInjectionExitBad.js#L17-L29) | `13` |
| [`functio ... true\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/Statements/UselessComparisonTest/constant.js#L1-L4) | `4` |
| [`functio ... n -1;\n}`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/Statements/UselessComparisonTest/example.js#L1-L12) | `12` |
| [`functio ... turn; }`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/Statements/UselessComparisonTest/tst.js#L8-L8) | `1` |
| [`functio ... i+1); }`](https://github.com/github/codeql/blob/cbdd4927cee593b715d8469240ce1d31edaaef9b/javascript/ql/test/query-tests/Statements/UselessComparisonTest/tst.js#L9-L9) | `1` |

View File

@@ -1 +1,6 @@
### meteor/meteor ### meteor/meteor
| c | |
| --- | --- |
| [`functio ... rn H\|0}`](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/logic-solver/minisat.js#L7-L7) | `1` |
| [`functio ... ext;\n\t}`](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/sha/sha256.js#L94-L124) | `31` |