-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathannotations.js
76 lines (66 loc) · 2.63 KB
/
annotations.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
let pluralToSingularMap = {
'functions': 'function',
'branches': 'branch',
'lines': 'line',
}
const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE;
function summarizeAnnotations(data) {
const formattedData = {};
Object.entries(data).forEach(([filename, annotations]) => {
const annotationMap = new Map();
annotations.forEach(annotation => {
const { lineNumber, annotationType } = annotation;
if (annotationMap.has(annotationType)) {
annotationMap.get(annotationType).push(lineNumber);
} else {
annotationMap.set(annotationType, [lineNumber]);
}
});
const formattedAnnotations = {};
annotationMap.forEach((lineNumbers, annotationType) => {
formattedAnnotations[annotationType] = lineNumbers;
});
formattedData[filename] = formattedAnnotations;
});
return formattedData;
}
function createAnnotations(uncoveredData, coverageType) {
let annotations = [];
if (coverageType === 'summarize') {
let summarizedData = summarizeAnnotations(uncoveredData);
console.log('summarizedData', summarizedData);
for (const file in summarizedData) {
let message = '';
Object.entries(summarizedData[file]).forEach(([annotationType, linesArray]) => {
message += `The ${annotationType} at place(s) ${linesArray.join(', ')} were not covered by any of the Tests.\n`;
});
console.log('message', message);
const filePathTrimmed = file.replace(`${GITHUB_WORKSPACE}/`, '');
annotations.push({
path: filePathTrimmed,
start_line: 1,
end_line: 1,
annotation_level: 'failure',
title: `** Summary of Uncovered Code **`,
message: message
})
}
} else if (coverageType === 'detailed') {
for (const file in uncoveredData) {
if (Array.isArray(uncoveredData[file])) {
uncoveredData[file].forEach(annotation => {
const filePathTrimmed = file.replace(`${GITHUB_WORKSPACE}/`, '');
annotations.push({
path: filePathTrimmed,
start_line: annotation.lineNumber,
end_line: annotation.lineNumber,
annotation_level: 'failure',
message: `${pluralToSingularMap[annotation.annotationType]} not covered!`
})
});
}
}
}
return annotations;
}
module.exports = createAnnotations;