@@ -216,6 +216,12 @@ def fmt_size(num: int) -> str:
216
216
217
217
218
218
GITHUB_API_ROOT = 'https://api.github.com'
219
+ COVERAGE_REGEXES = (
220
+ # for coverage
221
+ re .compile (r'<span\s+class="pc_cov">\s*([\d.]+)%\s*</span>' ),
222
+ # for diff-cover
223
+ re .compile (r'<li><b>Coverage</b>: *([\d.]+)%</li>' ),
224
+ )
219
225
220
226
221
227
def get_github_status_info (path : Path , description : str , coverage_threshold : Optional [float ]) -> tuple [str , str ]:
@@ -226,14 +232,16 @@ def get_github_status_info(path: Path, description: str, coverage_threshold: Opt
226
232
cov_sub = '{COVERAGE NOT FOUND}'
227
233
index_path = path / 'index.html'
228
234
if index_path .is_file ():
229
- m = re .search (r'<span\s+class="pc_cov">\s*([\d.]+)%\s*</span>' , index_path .read_text ())
230
- if m :
231
- coverage = float (m .group (1 ))
232
- if coverage_threshold is not None and coverage < coverage_threshold :
233
- state = 'failure'
234
- cov_sub = f'{ coverage :0.2f} % < { coverage_threshold :0.2f} %'
235
- else :
236
- cov_sub = f'{ coverage :0.2f} %'
235
+ for regex in COVERAGE_REGEXES :
236
+ m = regex .search (index_path .read_text ())
237
+ if m :
238
+ coverage = float (m .group (1 ))
239
+ if coverage_threshold is not None and coverage < coverage_threshold :
240
+ state = 'failure'
241
+ cov_sub = f'{ coverage :0.2f} % < { coverage_threshold :0.2f} %'
242
+ else :
243
+ cov_sub = f'{ coverage :0.2f} %'
244
+ break
237
245
238
246
description = re .sub ('{coverage-percentage}' , cov_sub , description , flags = re .I )
239
247
return state , description
0 commit comments