-
Notifications
You must be signed in to change notification settings - Fork 32
/
comment.md.j2
265 lines (221 loc) · 12.3 KB
/
comment.md.j2
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
{%- block title -%}## Coverage report{%- if subproject_id %} ({{ subproject_id }}){%- endif -%}{%- endblock title%}
{# Coverage evolution badge #}
{% block coverage_badges -%}
{%- block coverage_evolution_badge -%}
{%- if previous_coverage_rate %}
{%- set text = "Coverage for the whole project went from " ~ (previous_coverage_rate | pct) ~ " to " ~ (coverage.info.percent_covered | pct) -%}
{%- set color = (coverage.info.percent_covered - previous_coverage_rate) | get_evolution_color(neutral_color='blue') -%}
<img title="{{ text }}" src="{{ 'Coverage evolution' | generate_badge(message=(previous_coverage_rate | pct(precision=0)) ~ ' > ' ~ coverage.info.percent_covered | pct(precision=0), color=color) }}">
{%- else -%}
{%- set text = "Coverage for the whole project is " ~ (coverage.info.percent_covered | pct) ~ ". Previous coverage rate is not available, cannot report on evolution." -%}
{%- set color = coverage.info.percent_covered | x100 | get_badge_color -%}
<img title="{{ text }}" src="{{ 'Coverage' | generate_badge(message=(coverage.info.percent_covered | pct(precision=0)), color=color) }}">
{%- endif -%}
{%- endblock coverage_evolution_badge -%}
{#- Coverage diff badge -#}
{#- space #} {# space -#}
{%- block diff_coverage_badge -%}
{%- set text = (diff_coverage.total_percent_covered | pct) ~ " of the statement lines added by this PR are covered" -%}
<img title="{{ text }}" src="{{ 'PR Coverage' | generate_badge(message=diff_coverage.total_percent_covered | pct(precision=0), color=diff_coverage.total_percent_covered | x100 | get_badge_color) }}">
{%- endblock diff_coverage_badge -%}
{%- endblock coverage_badges -%}
{%- macro statements_badge(path, statements_count, previous_statements_count) -%}
{% if previous_statements_count is not none -%}
{% set statements_diff = statements_count - previous_statements_count %}
{% if statements_diff > 0 -%}
{% set text = "This PR adds " ~ statements_diff ~ " to the number of statements in " ~ path ~ ", taking it from " ~ previous_statements_count ~ " to " ~ statements_count ~"." -%}
{% set color = "007ec6" -%}
{% elif statements_diff < 0 -%}
{% set text = "This PR removes " ~ (-statements_diff) ~ " from the number of statements in " ~ path ~ ", taking it from " ~ previous_statements_count ~ " to " ~ statements_count ~"." -%}
{% set color = "49c2ee" -%}
{% else -%}
{% set text = "This PR doesn't change the number of statements in " ~ path ~ ", which is " ~ statements_count ~ "." -%}
{% set color = "5d89ba" -%}
{% endif -%}
{% set message = statements_diff %}
{% else -%}
{% set text = "This PR adds " ~ statements_count ~ " statement" ~ (statements_count | pluralize) ~ " to " ~ path ~ ". The file did not seem to exist on the base branch." -%}
{% set color = "007ec6" -%}
{% set message = statements_count %}
{% endif -%}
<td align="center"><a href="{{ path | file_url }}"><img title="{{ text }}" src="{{ statements_count | compact | generate_badge(message=(message | delta), color=color) }}"></a></td>
{%- endmacro -%}
{%- macro missing_lines_badge(path, missing_lines_count, previous_missing_lines_count) -%}
{%- if previous_missing_lines_count is not none -%}
{%- set missing_diff = missing_lines_count - previous_missing_lines_count %}
{%- if missing_diff > 0 -%}
{%- set text = "This PR adds " ~ missing_diff ~ " to the number of statements missing coverage in " ~ path ~ ", taking it from " ~ previous_missing_lines_count ~ " to " ~ missing_lines_count ~ "." -%}
{%- elif missing_diff < 0 -%}
{%- set text = "This PR removes " ~ (-missing_diff) ~ " from the number of statements missing coverage in " ~ path ~ ", taking it from " ~ previous_missing_lines_count ~ " to " ~ missing_lines_count ~ "." -%}
{%- else -%}
{%- set text = "This PR doesn't change the number of statements missing coverage in " ~ path ~ ", which is " ~ missing_lines_count ~ "." -%}
{%- endif -%}
{%- set message = missing_diff -%}
{%- else -%}
{%- set text = "This PR adds " ~ missing_lines_count ~ " statement" ~ (statements_count | pluralize) ~ " missing coverage to " ~ path ~ ". The file did not seem to exist on the base branch." -%}
{%- set message = missing_lines_count -%}
{%- endif -%}
{%- set color = message | get_evolution_color(up_is_good=false) -%}
<td align="center"><a href="{{ path | file_url }}"><img title="{{ text }}" src="{{ missing_lines_count | compact | generate_badge(message=(message | delta), color=color) }}"></a></td>
{%- endmacro -%}
{%- macro coverage_rate_badge(path, previous_percent_covered, previous_covered_statements_count, previous_statements_count, percent_covered, covered_statements_count, statements_count) -%}
{%- if previous_percent_covered is not none -%}
{%- set coverage_diff = percent_covered - previous_percent_covered -%}
{%- if coverage_diff > 0 -%}
{%- set text = "This PR adds " ~ ("{:.02f}".format(coverage_diff * 100)) ~ " percentage points to the coverage rate in " ~ path ~ ", taking it from " ~ previous_percent_covered | pct ~ " (" ~ previous_covered_statements_count ~ "/" ~ previous_statements_count ~ ") to " ~ percent_covered | pct ~ " (" ~ covered_statements_count ~ "/" ~ statements_count ~ ")." -%}
{%- elif coverage_diff < 0 -%}
{%- set text = "This PR removes " ~ ("{:.02f}".format(-coverage_diff * 100)) ~ " percentage points from the coverage rate in " ~ path ~ ", taking it from " ~ previous_percent_covered | pct ~ " (" ~ previous_covered_statements_count ~ "/" ~ previous_statements_count ~ ") to " ~ percent_covered | pct ~ " (" ~ covered_statements_count ~ "/" ~ statements_count ~ ")." -%}
{%- else -%}
{%- set text = "This PR doesn't change the coverage rate in " ~ path ~ ", which is " ~ percent_covered | pct ~ " (" ~ covered_statements_count ~ "/" ~ statements_count ~ ")." -%}
{%- endif -%}
{%- set color = coverage_diff | get_evolution_color() -%}
{%- set message = "(" ~ previous_covered_statements_count | compact ~ "/" ~ previous_statements_count | compact ~ " > " ~ covered_statements_count | compact ~ "/" ~ statements_count | compact ~ ")" -%}
{%- else -%}
{%- set text = "The coverage rate of " ~ path ~ " is " ~ percent_covered | pct ~ " (" ~ covered_statements_count ~ "/" ~ statements_count ~ "). The file did not seem to exist on the base branch." -%}
{%- set message = "(" ~ covered_statements_count | compact ~ "/" ~ statements_count | compact ~ ")" -%}
{%- set color = percent_covered | x100 | get_badge_color -%}
{%- endif -%}
<td align="center"><a href="{{ path | file_url }}"><img title="{{ text }}" src="{{ percent_covered | pct(precision=0) | generate_badge(message=message, color=color) }}"></a></td>
{%- endmacro -%}
{%- macro diff_coverage_rate_badge(path, added_statements_count, covered_statements_count, percent_covered) -%}
{% if added_statements_count -%}
{% set text = "In this PR, " ~ (added_statements_count) ~ " new statements are added to " ~ path ~ ", " ~ covered_statements_count ~ " of which are covered (" ~ (percent_covered | pct) ~ ")." -%}
{% set label = (percent_covered | pct(precision=0)) -%}
{% set message = "(" ~ covered_statements_count | compact ~ "/" ~ added_statements_count | compact ~ ")" -%}
{%- set color = (percent_covered | x100 | get_badge_color()) -%}
{% else -%}
{% set text = "This PR does not seem to add statements to " ~ path ~ "." -%}
{% set label = "" -%}
{%- set color = "grey" -%}
{% set message = "N/A" -%}
{% endif -%}
<td align="center"><a href="{{ path | file_url }}"><img title="{{ text }}" src="{{ label | generate_badge(message=message, color=color) }}"></a></td>
{%- endmacro -%}
{# Individual file report #}
{%- block coverage_by_file -%}
{%- if not files %}
_This PR does not seem to contain any modification to coverable code._
{%- else -%}
<details><summary>Click to see where and how coverage changed</summary><table><thead>
<tr><th>File</th><th>Statements</th><th>Missing</th><th>Coverage</th><th>Coverage<br>(new stmts)</th><th>Lines missing</th></tr>
</thead>
<tbody>
{%- for parent, files_in_folder in files|groupby(attribute="path.parent") -%}
<tr>
<td colspan="6"> <b>{{ parent }}</b></td>
{%- for file in files_in_folder -%}
{%- set path = file.coverage.path -%}
<tr>
<td> <a href="{{ path | file_url }}">{{ path.name }}</a></td>
{#- Statements cell -#}
{%- block statements_badge_cell scoped -%}
{{- statements_badge(
path=path,
statements_count=file.coverage.info.num_statements,
previous_statements_count=(file.previous.info.num_statements if file.previous else none),
) -}}
{%- endblock statements_badge_cell-%}
{#- Missing cell -#}
{%- block missing_lines_badge_cell scoped -%}
{{- missing_lines_badge(
path=path,
missing_lines_count=file.coverage.info.missing_lines,
previous_missing_lines_count=(file.previous.info.missing_lines if file.previous else none),
) -}}
{%- endblock missing_lines_badge_cell -%}
{#- Coverage rate -#}
{%- block coverage_rate_badge_cell scoped -%}
{{- coverage_rate_badge(
path=path,
previous_percent_covered=(file.previous.info.percent_covered if file.previous else none),
previous_covered_statements_count=(file.previous.info.covered_lines if file.previous else none),
previous_statements_count=(file.previous.info.num_statements if file.previous else none),
percent_covered=file.coverage.info.percent_covered,
covered_statements_count=file.coverage.info.covered_lines,
statements_count=file.coverage.info.num_statements,
) -}}
{%- endblock coverage_rate_badge_cell -%}
{#- Coverage of added lines -#}
{%- block diff_coverage_rate_badge_cell scoped -%}
{{- diff_coverage_rate_badge(
path=path,
added_statements_count=((file.diff.added_statements | length) if file.diff else none),
covered_statements_count=((file.diff.covered_statements | length) if file.diff else none),
percent_covered=(file.diff.percent_covered if file.diff else none)
) -}}
{%- endblock diff_coverage_rate_badge_cell -%}
{#- Link to missing lines -#}
{%- block link_to_missing_diff_lines_cell scoped -%}
<td>
{%- set comma = joiner() -%}
{%- for group in missing_diff_lines.get(path, []) -%}
{{- comma() -}}
<a href="{{ path | file_url(lines=(group.line_start, group.line_end))}}">
{{- group.line_start -}}
{%- if group.line_start != group.line_end -%}
-
{{- group.line_end -}}
{%- endif -%}
</a>
{%- endfor -%}
</td>
{%- endblock link_to_missing_diff_lines_cell -%}
{%- endfor -%}
{%- endfor -%}
</tbody>
<tfoot>
<tr>
<td><b>Project Total</b></td>
{#- Statements cell -#}
{%- block statements_badge_total_cell scoped -%}
{{- statements_badge(
path="the whole project",
statements_count=coverage.info.num_statements,
previous_statements_count=(previous_coverage.info.num_statements if previous_coverage else none),
) -}}
{%- endblock statements_badge_total_cell -%}
{#- Missing cell -#}
{%- block missing_lines_badge_total_cell scoped -%}
{{- missing_lines_badge(
path="the whole project",
missing_lines_count=coverage.info.missing_lines,
previous_missing_lines_count=(previous_coverage.info.missing_lines if previous_coverage else none),
) -}}
{%- endblock missing_lines_badge_total_cell -%}
{#- Coverage rate -#}
{%- block coverage_rate_badge_total_cell scoped -%}
{{- coverage_rate_badge(
path="the whole project",
previous_percent_covered=(previous_coverage.info.percent_covered if previous_coverage else none),
previous_covered_statements_count=(previous_coverage.info.covered_lines if previous_coverage else none),
previous_statements_count=(previous_coverage.info.num_statements if previous_coverage else none),
percent_covered=coverage.info.percent_covered,
covered_statements_count=coverage.info.covered_lines,
statements_count=coverage.info.num_statements,
) -}}
{%- endblock coverage_rate_badge_total_cell -%}
{# Coverage of added lines #}
{%- block diff_coverage_rate_badge_total_cell scoped -%}
{{- diff_coverage_rate_badge(
path="the whole project",
added_statements_count=diff_coverage.total_num_lines,
covered_statements_count=(diff_coverage.total_num_lines-diff_coverage.total_num_violations),
percent_covered=diff_coverage.total_percent_covered,
) -}}
{%- endblock diff_coverage_rate_badge_total_cell -%}
<td> </td>
</tr>
</tfoot>
</table>
{%- if max_files and count_files > max_files %}
_The report is truncated to {{ max_files }} files out of {{ count_files }}. To see the full report, please visit the workflow summary page._
{% endif %}
{%- block footer %}
<sub>
This report was generated by [python-coverage-comment-action](https://github.com/py-cov-action/python-coverage-comment-action)
</sub>
</details>
{% endblock footer -%}
{%- endif -%}
{%- endblock coverage_by_file %}
{{ marker -}}