From 29181465cb4fdd4614cc75ba933083d2b12f4ada Mon Sep 17 00:00:00 2001 From: Keunhyung Chung Date: Fri, 16 Feb 2024 11:31:53 +0900 Subject: [PATCH 01/10] Use the original `percent_covered` --- coverage_comment/coverage.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index 564649a5..e4472e89 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -194,10 +194,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=file_data["summary"]["covered_lines"], num_statements=file_data["summary"]["num_statements"], - percent_covered=compute_coverage( - file_data["summary"]["covered_lines"], - file_data["summary"]["num_statements"], - ), + percent_covered=file_data["summary"]["percent_covered"], missing_lines=file_data["summary"]["missing_lines"], excluded_lines=file_data["summary"]["excluded_lines"], num_branches=file_data["summary"].get("num_branches"), @@ -213,10 +210,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=data["totals"]["covered_lines"], num_statements=data["totals"]["num_statements"], - percent_covered=compute_coverage( - data["totals"]["covered_lines"], - data["totals"]["num_statements"], - ), + percent_covered=data["totals"]["percent_covered"], missing_lines=data["totals"]["missing_lines"], excluded_lines=data["totals"]["excluded_lines"], num_branches=data["totals"].get("num_branches"), From ff5f11294d22d61f473c4d00a7957d1301f223f8 Mon Sep 17 00:00:00 2001 From: Keunhyung Chung Date: Fri, 16 Feb 2024 11:39:18 +0900 Subject: [PATCH 02/10] Use `decimal.Decimal` --- coverage_comment/coverage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index e4472e89..41f1734e 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -194,7 +194,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=file_data["summary"]["covered_lines"], num_statements=file_data["summary"]["num_statements"], - percent_covered=file_data["summary"]["percent_covered"], + percent_covered=decimal.Decimal(file_data["summary"]["percent_covered"] / 100), missing_lines=file_data["summary"]["missing_lines"], excluded_lines=file_data["summary"]["excluded_lines"], num_branches=file_data["summary"].get("num_branches"), @@ -210,7 +210,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=data["totals"]["covered_lines"], num_statements=data["totals"]["num_statements"], - percent_covered=data["totals"]["percent_covered"], + percent_covered=decimal.Decimal(data["totals"]["percent_covered"] / 100), missing_lines=data["totals"]["missing_lines"], excluded_lines=data["totals"]["excluded_lines"], num_branches=data["totals"].get("num_branches"), From 627316932674a025f9f682de5b36cfa14ed1658f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 02:39:22 +0000 Subject: [PATCH 03/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- coverage_comment/coverage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index 41f1734e..e9ec2b66 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -194,7 +194,9 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=file_data["summary"]["covered_lines"], num_statements=file_data["summary"]["num_statements"], - percent_covered=decimal.Decimal(file_data["summary"]["percent_covered"] / 100), + percent_covered=decimal.Decimal( + file_data["summary"]["percent_covered"] / 100 + ), missing_lines=file_data["summary"]["missing_lines"], excluded_lines=file_data["summary"]["excluded_lines"], num_branches=file_data["summary"].get("num_branches"), From ee051b1d46e848fb76f11b39634bc161fb8c3648 Mon Sep 17 00:00:00 2001 From: Keunhyung Chung Date: Fri, 16 Feb 2024 11:43:22 +0900 Subject: [PATCH 04/10] Round number --- coverage_comment/coverage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index e9ec2b66..a2e9a529 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -195,7 +195,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: covered_lines=file_data["summary"]["covered_lines"], num_statements=file_data["summary"]["num_statements"], percent_covered=decimal.Decimal( - file_data["summary"]["percent_covered"] / 100 + round(file_data["summary"]["percent_covered"] / 100, ndigits=2) ), missing_lines=file_data["summary"]["missing_lines"], excluded_lines=file_data["summary"]["excluded_lines"], @@ -212,7 +212,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=data["totals"]["covered_lines"], num_statements=data["totals"]["num_statements"], - percent_covered=decimal.Decimal(data["totals"]["percent_covered"] / 100), + percent_covered=decimal.Decimal(round(data["totals"]["percent_covered"] / 100, ndigits=2)), missing_lines=data["totals"]["missing_lines"], excluded_lines=data["totals"]["excluded_lines"], num_branches=data["totals"].get("num_branches"), From 6dc7f8d2a07deb0f4d94862c6bd30c64b66ba4fa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 02:43:27 +0000 Subject: [PATCH 05/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- coverage_comment/coverage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index a2e9a529..0c95e378 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -212,7 +212,9 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: info=CoverageInfo( covered_lines=data["totals"]["covered_lines"], num_statements=data["totals"]["num_statements"], - percent_covered=decimal.Decimal(round(data["totals"]["percent_covered"] / 100, ndigits=2)), + percent_covered=decimal.Decimal( + round(data["totals"]["percent_covered"] / 100, ndigits=2) + ), missing_lines=data["totals"]["missing_lines"], excluded_lines=data["totals"]["excluded_lines"], num_branches=data["totals"].get("num_branches"), From 1a8904ed69b602f133fdc2843231134a2d5a2d7b Mon Sep 17 00:00:00 2001 From: Keunhyung Chung Date: Fri, 16 Feb 2024 12:03:51 +0900 Subject: [PATCH 06/10] Use `str` --- coverage_comment/coverage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index 0c95e378..192d6aff 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -195,7 +195,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: covered_lines=file_data["summary"]["covered_lines"], num_statements=file_data["summary"]["num_statements"], percent_covered=decimal.Decimal( - round(file_data["summary"]["percent_covered"] / 100, ndigits=2) + str(round(file_data["summary"]["percent_covered"] / 100, ndigits=2)) ), missing_lines=file_data["summary"]["missing_lines"], excluded_lines=file_data["summary"]["excluded_lines"], @@ -213,7 +213,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: covered_lines=data["totals"]["covered_lines"], num_statements=data["totals"]["num_statements"], percent_covered=decimal.Decimal( - round(data["totals"]["percent_covered"] / 100, ndigits=2) + str(round(data["totals"]["percent_covered"] / 100, ndigits=2)) ), missing_lines=data["totals"]["missing_lines"], excluded_lines=data["totals"]["excluded_lines"], From 55a23fd23989878a88985333a2da40d5e2ceefbf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 03:03:56 +0000 Subject: [PATCH 07/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- coverage_comment/coverage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index 192d6aff..4ef06832 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -195,7 +195,11 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: covered_lines=file_data["summary"]["covered_lines"], num_statements=file_data["summary"]["num_statements"], percent_covered=decimal.Decimal( - str(round(file_data["summary"]["percent_covered"] / 100, ndigits=2)) + str( + round( + file_data["summary"]["percent_covered"] / 100, ndigits=2 + ) + ) ), missing_lines=file_data["summary"]["missing_lines"], excluded_lines=file_data["summary"]["excluded_lines"], From 88e986b3668407b022f3cd8bccf883f4e88585ae Mon Sep 17 00:00:00 2001 From: Keunhyung Chung Date: Fri, 16 Feb 2024 12:08:27 +0900 Subject: [PATCH 08/10] Divide by 100 after round --- coverage_comment/coverage.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index 4ef06832..84c3eed5 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -197,8 +197,8 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: percent_covered=decimal.Decimal( str( round( - file_data["summary"]["percent_covered"] / 100, ndigits=2 - ) + file_data["summary"]["percent_covered"], ndigits=2 + ) / 100 ) ), missing_lines=file_data["summary"]["missing_lines"], @@ -217,7 +217,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: covered_lines=data["totals"]["covered_lines"], num_statements=data["totals"]["num_statements"], percent_covered=decimal.Decimal( - str(round(data["totals"]["percent_covered"] / 100, ndigits=2)) + str(round(data["totals"]["percent_covered"], ndigits=2) / 100) ), missing_lines=data["totals"]["missing_lines"], excluded_lines=data["totals"]["excluded_lines"], From 688cfd0b63fa69cbf364ff37879c91fba92366fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 03:08:31 +0000 Subject: [PATCH 09/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- coverage_comment/coverage.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/coverage_comment/coverage.py b/coverage_comment/coverage.py index 84c3eed5..a064081b 100644 --- a/coverage_comment/coverage.py +++ b/coverage_comment/coverage.py @@ -196,9 +196,8 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage: num_statements=file_data["summary"]["num_statements"], percent_covered=decimal.Decimal( str( - round( - file_data["summary"]["percent_covered"], ndigits=2 - ) / 100 + round(file_data["summary"]["percent_covered"], ndigits=2) + / 100 ) ), missing_lines=file_data["summary"]["missing_lines"], From 5fad825731fe95cebbd0697ce4b1efd5497f270c Mon Sep 17 00:00:00 2001 From: Keunhyung Chung Date: Fri, 16 Feb 2024 12:16:30 +0900 Subject: [PATCH 10/10] Update test case number --- tests/integration/test_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py index 10e563fa..cdba7ae3 100644 --- a/tests/integration/test_main.py +++ b/tests/integration/test_main.py @@ -192,7 +192,7 @@ def checker(payload): assert comment == comment_file assert comment == summary_file.read_text() assert ( - "Coverage for the whole project is 77.77%. Previous coverage rate is not available" + "Coverage for the whole project is 77.78%. Previous coverage rate is not available" in comment ) assert ( @@ -331,7 +331,7 @@ def checker(payload): assert result == 0 assert not pathlib.Path("python-coverage-comment-action.txt").exists() - assert "Coverage for the whole project went from 30% to 77.77%" in comment + assert "Coverage for the whole project went from 30% to 77.78%" in comment assert comment.count("