mirror of
https://github.com/grafana/grafana.git
synced 2024-11-21 16:38:03 -06:00
Chore: change bettererResultsToJSON
format (#86381)
This commit is contained in:
parent
9b27d5a0c1
commit
3bb6de57d2
15589
.betterer.results.json
15589
.betterer.results.json
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,16 @@
|
||||
import { BettererFileIssue, betterer } from '@betterer/betterer';
|
||||
import { betterer } from '@betterer/betterer';
|
||||
import { writeFile } from 'fs/promises';
|
||||
|
||||
interface Issue {
|
||||
message: string;
|
||||
count: string;
|
||||
interface FilesByIssues {
|
||||
name: string;
|
||||
files: [
|
||||
{
|
||||
path: string;
|
||||
count: number;
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
type ResultMap = Record<string, Record<string, Issue[]>>;
|
||||
type ResultMap = Record<string, FilesByIssues[]>;
|
||||
|
||||
/**
|
||||
* Produces a JSON file for consumption directly in Grafana
|
||||
@ -16,23 +20,30 @@ async function main() {
|
||||
const resultMap: ResultMap = {};
|
||||
|
||||
for (const suite of results.resultSummaries) {
|
||||
resultMap[suite.name] = {};
|
||||
|
||||
// Aggregate issues for each file in the suite
|
||||
resultMap[suite.name] = [];
|
||||
const filesByIssues: FilesByIssues[] = [];
|
||||
// Group by message in the suite, then by file counting the number of occurrences
|
||||
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;
|
||||
details.forEach((element) => {
|
||||
const messageExist = filesByIssues.some((issue) => issue.name === element.message);
|
||||
// If the message does not exist, add it to the list of issues
|
||||
// With the file and start the count at 1
|
||||
if (!messageExist) {
|
||||
const name: FilesByIssues['name'] = element.message;
|
||||
filesByIssues.push({ name, files: [{ path: relativePath, count: 1 }] });
|
||||
} else {
|
||||
//If it exists, check if there is a file with the same path
|
||||
//If so, increment the count, if not, add the file to the list starting the count at 1
|
||||
const issue = filesByIssues.find((issue) => issue.name === element.message);
|
||||
if (issue?.files.find((file) => file.path === relativePath)?.count !== undefined) {
|
||||
issue.files.find((file) => file.path === relativePath)!.count++;
|
||||
} else {
|
||||
issue?.files.push({ path: relativePath, count: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
resultMap[suite.name] = filesByIssues;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user