From cdf71fa1873a3c1e9e0a8fedca92326904b04c7c Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Sun, 10 Sep 2023 13:10:41 +0200 Subject: [PATCH] Addressing the issue of PRs not targetting the default branch --- coverage_comment/main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/coverage_comment/main.py b/coverage_comment/main.py index a354d6e3..abfca7f3 100644 --- a/coverage_comment/main.py +++ b/coverage_comment/main.py @@ -119,11 +119,17 @@ def process_pr( base_ref=base_ref, coverage_path=config.COVERAGE_PATH ) - previous_coverage_data_file = storage.get_datafile_contents( - github=gh, - repository=config.GITHUB_REPOSITORY, - branch=config.COVERAGE_DATA_BRANCH, - ) + # It only really makes sense to display a comparison with the previous + # coverage if the PR target is the branch in which the coverage data is + # stored, e.g. the default branch. + previous_coverage_data_file = None + if base_ref == repo_info.default_branch: + previous_coverage_data_file = storage.get_datafile_contents( + github=gh, + repository=config.GITHUB_REPOSITORY, + branch=config.COVERAGE_DATA_BRANCH, + ) + previous_coverage = None if previous_coverage_data_file: previous_coverage = files.parse_datafile(contents=previous_coverage_data_file)