add a docs macro that outputs a JSON badge:
@env.macro
def get_coverage():
data = json.load(Path("htmlcov/coverage.json").read_text())
value = int(data["totals"]["percent_covered"])
for threshold, hex in (
(95, "#4c1"), # brightgreen
(90, "#97CA00"), # green
(75, "#a4a61d"), # yellowgreen
(60, "#dfb317"), # yellow
(40, "#fe7d37"), # orange
(0, "#e05d44"), # red
):
if value >= threshold:
color = hex
break
return {"value": value, "color": color}
add a templated file coverage_badge.json
to the docs:
{% with get_coverage() as coverage %}
{"schemaVersion": 1, "label": "coverage", "message": "{{ coverage.value }}", "color": "{{ coverage.color }}"}
{% endwith %}
add a badge to the readme pointing to that published JSON file:
[![coverage](https://img.shields.io/endpoint?url=https://namespace.github.io/project/coverage_badge.json)](https://namespace.github.io/project/coverage)
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too