Repository: cpp-linter/cpp-linter (language: python)

Issue:
optionally exclude suggestions in the PR review (using env var)
As I typed that list of caveats, I thought that it might be desirable to have only the PR review's summary comment (with no suggestions shown in the diff). To do that, I would probably support a env var named `CPP_LINTER_PR_REVIEW_NO_SUGGESTION`. That should help reduce PR thread pollution.

_Originally posted by @2bndy5 in https://github.com/cpp-linter/cpp-linter-action/issues/182#issuecomment-1893303567_
            


Discussion / hints:
I think `CPP_LINTER_PR_REVIEW_SUMMARY_ONLY` might be a better env var name. It would be used in workflows like so:
```yml
- uses: cpp-linter/cpp-linter-action@v2
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    CPP_LINTER_PR_REVIEW_SUMMARY_ONLY: true
  with:
    tidy-review: true
```

Fix patch:
diff --git a/cpp_linter/rest_api/github_api.py b/cpp_linter/rest_api/github_api.py
index eee21b65..715be1d9 100644
--- a/cpp_linter/rest_api/github_api.py
+++ b/cpp_linter/rest_api/github_api.py
@@ -376,18 +376,24 @@ def post_review(
         body = f"{COMMENT_MARKER}## Cpp-linter Review\n"
         payload_comments = []
         total_changes = 0
+        summary_only = (
+            environ.get("CPP_LINTER_PR_REVIEW_SUMMARY_ONLY", "false") == "true"
+        )
         advice: Dict[str, Sequence[Union[TidyAdvice, FormatAdvice]]] = {}
         if format_review:
             advice["clang-format"] = format_advice
         if tidy_review:
             advice["clang-tidy"] = tidy_advice
         for tool_name, tool_advice in advice.items():
-            comments, total, patch = self.create_review_comments(files, tool_advice)
+            comments, total, patch = self.create_review_comments(
+                files, tool_advice, summary_only
+            )
             total_changes += total
-            payload_comments.extend(comments)
-            if total and total != len(comments):
-                body += f"Only {len(comments)} out of {total} {tool_name} "
-                body += "suggestions fit within this pull request's diff.\n"
+            if not summary_only:
+                payload_comments.extend(comments)
+                if total and total != len(comments):
+                    body += f"Only {len(comments)} out of {total} {tool_name} "
+                    body += "suggestions fit within this pull request's diff.\n"
             if patch:
                 body += f"\n<details><summary>Click here for the full {tool_name} patch"
                 body += f"</summary>\n\n\n```diff\n{patch}\n```\n\n\n</details>\n\n"
@@ -413,6 +419,7 @@ def post_review(
     def create_review_comments(
         files: List[FileObj],
         tool_advice: Sequence[Union[FormatAdvice, TidyAdvice]],
+        summary_only: bool,
     ) -> Tuple[List[Dict[str, Any]], int, str]:
         """Creates a batch of comments for a specific clang tool's PR review"""
         total = 0
@@ -430,6 +437,8 @@ def create_review_comments(
             full_patch += patch.text
             for hunk in patch.hunks:
                 total += 1
+                if summary_only:
+                    continue
                 new_hunk_range = file.is_hunk_contained(hunk)
                 if new_hunk_range is None:
                     continue


Test patch:
diff --git a/tests/reviews/test_pr_review.py b/tests/reviews/test_pr_review.py
index 36efa13a..71c22111 100644
--- a/tests/reviews/test_pr_review.py
+++ b/tests/reviews/test_pr_review.py
@@ -13,18 +13,19 @@
 
 
 @pytest.mark.parametrize(
-    "is_draft,is_closed,with_token,force_approved,tidy_review,format_review,changes",
+    "is_draft,is_closed,with_token,force_approved,tidy_review,format_review,changes,summary_only",
     [
-        (True, False, True, False, False, True, 2),
-        (False, True, True, False, False, True, 2),
+        (True, False, True, False, False, True, 2, False),
+        (False, True, True, False, False, True, 2, False),
         pytest.param(
-            False, False, False, False, False, True, 2, marks=pytest.mark.xfail
+            False, False, False, False, False, True, 2, False, marks=pytest.mark.xfail
         ),
-        (False, False, True, True, False, True, 2),
-        (False, False, True, False, True, False, 2),
-        (False, False, True, False, False, True, 2),
-        (False, False, True, False, True, True, 1),
-        (False, False, True, False, True, True, 0),
+        (False, False, True, True, False, True, 2, False),
+        (False, False, True, False, True, False, 2, False),
+        (False, False, True, False, False, True, 2, False),
+        (False, False, True, False, True, True, 1, False),
+        (False, False, True, False, True, True, 0, False),
+        (False, False, True, False, True, True, 0, True),
     ],
     ids=[
         "draft",
@@ -35,6 +36,7 @@
         "format",  # changes == diff_chunks only
         "lines_added",
         "all_lines",
+        "summary_only",
     ],
 )
 def test_post_review(
@@ -47,6 +49,7 @@ def test_post_review(
     format_review: bool,
     force_approved: bool,
     changes: int,
+    summary_only: bool,
 ):
     """A mock test of posting PR reviews"""
     # patch env vars
@@ -57,6 +60,8 @@ def test_post_review(
     monkeypatch.setenv("CI", "true")
     if with_token:
         monkeypatch.setenv("GITHUB_TOKEN", "123456")
+    if summary_only:
+        monkeypatch.setenv("CPP_LINTER_PR_REVIEW_SUMMARY_ONLY", "true")
     monkeypatch.chdir(str(tmp_path))
     (tmp_path / "src").mkdir()
     demo_dir = Path(__file__).parent.parent / "demo"