-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathparse-results.ts
More file actions
31 lines (27 loc) · 924 Bytes
/
parse-results.ts
File metadata and controls
31 lines (27 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { CheckResult } from './pr-comment-formatter';
/**
* Parses the results file content produced by the WordPress Plugin Check action.
*
* The file format consists of alternating lines:
* - A line starting with "FILE: " followed by the file path
* - A JSON array of CheckResult objects for that file
*
* @param content - The full text content of the results file
* @returns A map from file path to its array of check results
*/
export function parseResultsFile(
content: string,
): Map<string, CheckResult[]> {
const fileResultsMap = new Map<string, CheckResult[]>();
const lines = content.split('\n');
for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i];
if (!line.startsWith('FILE: ')) {
continue;
}
const fileName = line.split('FILE: ')[1];
const results: CheckResult[] = JSON.parse(lines[++i]) || [];
fileResultsMap.set(fileName, results);
}
return fileResultsMap;
}