mirror of https://github.com/grafana/grafana
Betterer: Expose results as JSON (#81352)
* Expose betterer results as JSON * Make prettier and add command * Add aggregation * Add json generation to lefthook * Use relative path * Add grafanabot as codeowner * Fix parameter type * Include changes to results * Run betterer:jsonpull/82441/head
parent
4cbc7dfb5b
commit
6ce286246b
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,42 @@ |
|||||||
|
import { BettererFileIssue, betterer } from '@betterer/betterer'; |
||||||
|
import { writeFile } from 'fs/promises'; |
||||||
|
|
||||||
|
interface Issue { |
||||||
|
message: string; |
||||||
|
count: string; |
||||||
|
} |
||||||
|
|
||||||
|
type ResultMap = Record<string, Record<string, Issue[]>>; |
||||||
|
|
||||||
|
/** |
||||||
|
* Produces a JSON file for consumption directly in Grafana |
||||||
|
*/ |
||||||
|
async function main() { |
||||||
|
const results = await betterer.results(); |
||||||
|
const resultMap: ResultMap = {}; |
||||||
|
|
||||||
|
for (const suite of results.resultSummaries) { |
||||||
|
resultMap[suite.name] = {}; |
||||||
|
|
||||||
|
// Aggregate issues for each file in the suite
|
||||||
|
for (const [file, details] of Object.entries(suite.details)) { |
||||||
|
const fileIssues: Issue[] = []; |
||||||
|
for (const issue of details) { |
||||||
|
const issueExists = fileIssues.find((i) => i.message === issue.message)!!; |
||||||
|
if (issueExists) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
fileIssues.push({ |
||||||
|
message: issue.message, |
||||||
|
count: details.filter((i: BettererFileIssue) => i.message === issue.message).length, |
||||||
|
}); |
||||||
|
} |
||||||
|
const relativePath = file.replace(process.cwd(), ''); |
||||||
|
resultMap[suite.name][relativePath] = fileIssues; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
await writeFile('.betterer.results.json', JSON.stringify(resultMap, undefined, 2)); |
||||||
|
} |
||||||
|
|
||||||
|
main().catch(console.error); |
Loading…
Reference in new issue