Skip to content

Commit

Permalink
Merge pull request #286 from py-cov-action/fix-285-push-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim authored Oct 13, 2023
2 parents 70b2d8a + b45ecb9 commit 8e1040d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion coverage_comment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def process_pr(
) -> int:
log.info("Generating comment for PR")

if not config.GITHUB_PR_NUMBER and not config.GITHUB_BRANCH_NAME:
log.info(
"This worflow is not triggered on a pull_request event, "
"nor on a push event on a branch. Consequently, there's nothing to do. "
"Exiting."
)
return 0

_, coverage = coverage_module.get_coverage_info(
merge=config.MERGE_COVERAGE_FILES,
coverage_path=config.COVERAGE_PATH,
Expand Down Expand Up @@ -177,7 +185,6 @@ def process_pr(
if pr_number is None:
# If we don't have a PR number, we're launched from a push event,
# so we need to find the PR number from the branch name
assert config.GITHUB_BRANCH_NAME
try:
pr_number = github.find_pr_for_branch(
github=gh,
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,25 @@ def checker(payload):
assert output_file.read_text() == expected_output


def test_action__push__no_branch(
push_config, session, in_integration_env, git, get_logs
):
session.register("GET", "/repos/py-cov-action/foobar")(
json={"default_branch": "main", "visibility": "public"}
)

result = main.action(
config=push_config(
GITHUB_REF="refs/tags/v1.0.0",
),
github_session=session,
http_session=session,
git=git,
)
assert result == 0
assert get_logs("INFO", "This worflow is not triggered on a pull_request event")


def test_action__push__non_default_branch__no_pr(
push_config, session, in_integration_env, output_file, summary_file, git
):
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,16 @@ def test_parse_diff_output(git):
pathlib.Path("README.md"): [1, 3, 4, 5, 6],
pathlib.Path("foo.txt"): [1],
}


def test_parse_diff_output__error(git):
diff = """
@@ -0,0 +1,1 @@
+name: Python Coverage Comment
diff --git a/README.md b/README.md
index 1f1d9a4..e69de29 100644
"""
git.register("git fetch origin main --depth=1000")()
git.register("git diff --unified=0 FETCH_HEAD -- .")(stdout=diff)
with pytest.raises(ValueError):
coverage.parse_diff_output(diff=diff)

0 comments on commit 8e1040d

Please sign in to comment.