Repository: py-cov-action/python-coverage-comment-action (python)

Issue:
Running coverage action in tag push events produce misleading error message
This [change](https://github.com/py-cov-action/python-coverage-comment-action/pull/248/files#diff-aa416c9a98a0fd16ca04ed4a3606bf634663109cd1562c05467181ad9b0a8a08R174) makes the coverage action produce a misleading error message about permissions, when the issue is that the event triggering the action does not relate to a pull request and/or branch:

```
2023-10-11T13:32:08.2937186Z ##[notice]Starting action
2023-10-11T13:32:08.6275828Z ##[notice]HTTP Request: GET https://api.github.com/repos/claranet/tfwrapper "HTTP/1.1 200 OK"
2023-10-11T13:32:08.6279564Z ##[notice]Generating comment for PR
2023-10-11T13:32:10.0641449Z ##[notice]HTTP Request: GET https://api.github.com/repos/claranet/tfwrapper/contents/data.json?ref=python-coverage-comment-action-data "HTTP/1.1 200 OK"
2023-10-11T13:32:10.0834693Z ##[error]Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 40, in main
    exit_code = action(
                ^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 92, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 180, in process_pr
    assert config.GITHUB_BRANCH_NAME
AssertionError

```

See this execution for example: https://github.com/claranet/tfwrapper/actions/runs/6483246492/job/17604440212#step:5:22

Pull request:
Don't crash on pushing when pushing on something else than a branch
Closes #285 .

Need to add a test, but otherwise, yeah.

Patch:
diff --git a/coverage_comment/main.py b/coverage_comment/main.py
index 39d4c84..60dfae1 100644
--- a/coverage_comment/main.py
+++ b/coverage_comment/main.py
@@ -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,
@@ -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,


Test patch:
diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py
index 20811c8..a653d9d 100644
--- a/tests/integration/test_main.py
+++ b/tests/integration/test_main.py
@@ -400,6 +400,25 @@ def test_action__push__non_default_branch(
     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
 ):
diff --git a/tests/unit/test_coverage.py b/tests/unit/test_coverage.py
index 05ab09e..e0760f0 100644
--- a/tests/unit/test_coverage.py
+++ b/tests/unit/test_coverage.py
@@ -287,3 +287,16 @@ rename to coverage_comment/annotations2.py
         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)