Skip to content

Commit

Permalink
Store COVERAGE_PATH on data branch (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieferro authored Sep 23, 2023
1 parent 81ee18f commit 526de47
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
14 changes: 12 additions & 2 deletions coverage_comment/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def apply(self):
def compute_files(
line_rate: decimal.Decimal,
raw_coverage_data: dict,
coverage_path: pathlib.Path,
minimum_green: decimal.Decimal,
minimum_orange: decimal.Decimal,
http_session: httpx.Client,
Expand All @@ -81,6 +82,7 @@ def compute_files(
contents=compute_datafile(
raw_coverage_data=raw_coverage_data,
line_rate=line_rate,
coverage_path=coverage_path,
),
),
WriteFile(
Expand All @@ -92,8 +94,16 @@ def compute_files(
]


def compute_datafile(raw_coverage_data: dict, line_rate: decimal.Decimal) -> str:
return json.dumps({"coverage": float(line_rate), "raw_data": raw_coverage_data})
def compute_datafile(
raw_coverage_data: dict, line_rate: decimal.Decimal, coverage_path: pathlib.Path
) -> str:
return json.dumps(
{
"coverage": float(line_rate),
"raw_data": raw_coverage_data,
"coverage_path": str(coverage_path),
}
)


def parse_datafile(contents) -> decimal.Decimal:
Expand Down
1 change: 1 addition & 0 deletions coverage_comment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def save_coverage_data_files(
operations: list[files.Operation] = files.compute_files(
line_rate=coverage.info.percent_covered,
raw_coverage_data=raw_coverage_data,
coverage_path=config.COVERAGE_PATH,
minimum_green=config.MINIMUM_GREEN,
minimum_orange=config.MINIMUM_ORANGE,
http_session=http_session,
Expand Down
1 change: 1 addition & 0 deletions tests/end_to_end/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_public_repo(
assert "coverage" in data
assert "raw_data" in data
assert "meta" in data["raw_data"]
assert "coverage_path" in data

endpoint = client.get(
f"{raw_url_prefix}/endpoint.json", follow_redirects=True
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_compute_files(session):
result = files.compute_files(
line_rate=decimal.Decimal("0.1234"),
raw_coverage_data={"foo": ["bar", "bar2"]},
coverage_path=pathlib.Path("."),
minimum_green=decimal.Decimal("25"),
minimum_orange=decimal.Decimal("70"),
http_session=session,
Expand All @@ -43,7 +44,7 @@ def test_compute_files(session):
),
files.WriteFile(
path=pathlib.Path("data.json"),
contents='{"coverage": 12.34, "raw_data": {"foo": ["bar", "bar2"]}}',
contents='{"coverage": 12.34, "raw_data": {"foo": ["bar", "bar2"]}, "coverage_path": "."}',
),
files.WriteFile(path=pathlib.Path("badge.svg"), contents="foo"),
]
Expand All @@ -55,8 +56,9 @@ def test_compute_datafile():
files.compute_datafile(
line_rate=decimal.Decimal("12.34"),
raw_coverage_data={"meta": {"version": "5.5"}},
coverage_path=pathlib.Path("./src/code"),
)
== """{"coverage": 12.34, "raw_data": {"meta": {"version": "5.5"}}}"""
== """{"coverage": 12.34, "raw_data": {"meta": {"version": "5.5"}}, "coverage_path": "src/code"}"""
)


Expand Down

0 comments on commit 526de47

Please sign in to comment.