-
Notifications
You must be signed in to change notification settings - Fork 36
/
.coverage-comment-template.svelte
194 lines (177 loc) · 6.34 KB
/
.coverage-comment-template.svelte
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<script>
export let total_statements_coverage_percent_raw;
export let total_branches_coverage_percent_raw;
export let total_functions_coverage_percent_raw;
export let total_lines_coverage_percent_raw;
export let base_total_statements_coverage_percent_raw;
export let base_total_branches_coverage_percent_raw;
export let base_total_functions_coverage_percent_raw;
export let base_total_lines_coverage_percent_raw;
export let commit_sha;
export let short_commit_sha;
export let commit_link;
export let base_commit_sha;
export let base_short_commit_sha;
export let base_commit_link;
export let base_ref;
export let changed_files_coverage_data;
const has_base_data = base_total_branches_coverage_percent_raw !== '?';
const summary_list = [
{
type: 'Total Statements Coverage',
percent: {
total: total_statements_coverage_percent_raw,
base: has_base_data ? base_total_statements_coverage_percent_raw : null,
diff: has_base_data
? total_statements_coverage_percent_raw -
base_total_statements_coverage_percent_raw
: null,
},
},
{
type: 'Total Branches Coverage',
percent: {
total: total_branches_coverage_percent_raw,
base: has_base_data ? base_total_branches_coverage_percent_raw : null,
diff: has_base_data
? total_branches_coverage_percent_raw - base_total_branches_coverage_percent_raw
: null,
},
},
{
type: 'Total Functions Coverage',
percent: {
total: total_functions_coverage_percent_raw,
base: has_base_data ? base_total_functions_coverage_percent_raw : null,
diff: has_base_data
? total_functions_coverage_percent_raw -
base_total_functions_coverage_percent_raw
: null,
},
},
{
type: 'Total Lines Coverage',
percent: {
total: total_lines_coverage_percent_raw,
base: has_base_data ? base_total_lines_coverage_percent_raw : null,
diff: has_base_data
? total_lines_coverage_percent_raw - base_total_lines_coverage_percent_raw
: null,
},
},
];
const LETTER_LABEL = {
S: 'Statements',
B: 'Branches',
F: 'Functions',
L: 'Lines',
};
const COVERAGE_LEVEL_IMAGE = {
low: 'https://user-images.githubusercontent.com/11299391/159445221-fe3dc085-8c56-4e03-9642-219784c88fe7.svg',
medium: 'https://user-images.githubusercontent.com/11299391/159445212-f135c6d7-f354-4e8c-9a9f-28bb3ff1b7b5.svg',
high: 'https://user-images.githubusercontent.com/11299391/159445220-d88b3624-0814-4664-80c8-09f0f2b8e68b.svg',
};
function formatPercentDiff(percent) {
if (!Number.isFinite(percent)) {
return '';
}
const roundedPercent = `${Number(percent.toFixed(2))}%`;
if (percent >= 0) {
return '+' + roundedPercent;
}
return roundedPercent;
}
function getCoverageLevelImage(percent) {
// https://github.com/istanbuljs/istanbuljs/blob/c1559005b3bb318da01f505740adb0e782aaf14e/packages/istanbul-lib-report/lib/watermarks.js
if (percent >= 80) {
return COVERAGE_LEVEL_IMAGE.high;
} else if (percent >= 50) {
return COVERAGE_LEVEL_IMAGE.medium;
} else {
return COVERAGE_LEVEL_IMAGE.low;
}
}
function getFilePrefix() {
return `../blob/${commit_sha}/`;
}
</script>
<h2>Coverage Report</h2>
Commit:<a href={commit_link}>{short_commit_sha}</a><br />
Base: <a href={base_commit_link}>{base_ref}@{base_short_commit_sha}</a><br /><br />
<table>
<thead>
<th>Type</th>
{#if has_base_data}
<th>Base</th>
{/if}
<th>This PR</th>
</thead>
<tbody>
{#each summary_list as { type, percent }}
<tr>
<td>{type}</td>
{#if has_base_data}
<td>
{#if Number.isFinite(percent.base)}
<img
src={getCoverageLevelImage(percent.base)}
alt=""
/> {percent.base}%
{:else}
-
{/if}
</td>
{/if}
<td>
{#if Number.isFinite(percent.total)}
<img
src={getCoverageLevelImage(percent.total)}
alt=""
/> {percent.total}%
{#if has_base_data}
({formatPercentDiff(percent.diff)})
{/if}
{:else}
-
{/if}
</td>
</tr>
{/each}
</tbody>
</table>
<details>
<summary>Details (changed files):</summary><br />
<table>
<thead>
<th>File</th>
<th>Statements</th>
<th>Branches</th>
<th>Functions</th>
<th>Lines</th>
</thead>
<tbody>
{#each changed_files_coverage_data as [file, data]}
{@const percents = [
data.statements.pct,
data.branches.pct,
data.functions.pct,
data.lines.pct,
]}
<tr>
<td>
<a href="{getFilePrefix()}{file}">{file}</a>
</td>
{#each percents as percent}
<td>
{#if Number.isFinite(percent)}
<img src={getCoverageLevelImage(percent)} alt="" /> {percent}%
{:else}
-
{/if}
</td>
{/each}
</tr>
{/each}
</tbody>
</table>
</details>