Skip to content

Commit 7dce923

Browse files
authored
document PR review feature caveats (#70)
This is mostly taken from a comment I posted in cpp-linter/cpp-linter-action#182 with some updates. Also reviewed other changes about the generated cli_args.rst document.
1 parent 608682a commit 7dce923

File tree

4 files changed

+102
-28
lines changed

4 files changed

+102
-28
lines changed

cpp_linter/cli.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
),
1515
formatter_class=argparse.RawTextHelpFormatter,
1616
)
17-
arg = cli_arg_parser.add_argument(
17+
cli_arg_parser.add_argument(
1818
"-v",
1919
"--verbosity",
2020
type=lambda a: a.lower() in ["debug", "10"],
@@ -61,7 +61,10 @@
6161
- Set this to ``file`` to have clang-format use the
6262
closest relative .clang-format file.
6363
- Set this to a blank string (``""``) to disable
64-
using clang-format entirely.""",
64+
using clang-format entirely.
65+
66+
See `clang-format docs <https://clang.llvm.org/docs/ClangFormat.html>`_ for more info.
67+
""",
6568
)
6669
cli_arg_parser.add_argument(
6770
"-c",
@@ -87,7 +90,7 @@
8790
8891
%(default)s
8992
90-
See also clang-tidy docs for more info.""",
93+
See also `clang-tidy docs <https://clang.llvm.org/extra/clang-tidy>`_ for more info.""",
9194
)
9295
arg = cli_arg_parser.add_argument(
9396
"-V",
@@ -105,7 +108,7 @@
105108
Default is """,
106109
)
107110
assert arg.help is not None
108-
arg.help += "a blank string." if not arg.default else f"``{arg.default}``."
111+
arg.help += f"``{repr(arg.default)}``."
109112
arg = cli_arg_parser.add_argument(
110113
"-e",
111114
"--extensions",
@@ -151,10 +154,10 @@
151154
- Glob patterns are not supported here. All asterisk
152155
characters (``*``) are literal.""",
153156
)
154-
arg = cli_arg_parser.add_argument(
157+
cli_arg_parser.add_argument(
155158
"-l",
156159
"--lines-changed-only",
157-
default=0,
160+
default="false",
158161
type=lambda a: 2 if a.lower() == "true" else int(a.lower() == "diff"),
159162
help="""This controls what part of the files are analyzed.
160163
The following values are accepted:
@@ -165,10 +168,8 @@
165168
- ``diff``: All lines in the diff are analyzed
166169
including unchanged lines but not subtractions.
167170
168-
Defaults to """,
171+
Defaults to ``%(default)s``.""",
169172
)
170-
assert arg.help is not None
171-
arg.help += f"``{str(bool(arg.default)).lower()}``."
172173
cli_arg_parser.add_argument(
173174
"-f",
174175
"--files-changed-only",
@@ -282,21 +283,21 @@
282283
explicitly ignored domains (see :std:option:`--ignore`).""",
283284
)
284285
cli_arg_parser.add_argument(
286+
"-d",
285287
"--tidy-review",
286-
"-tr",
287288
default="false",
288289
type=lambda input: input.lower() == "true",
289-
help="""Set to ``true`` to enable PR review suggestions
290+
help="""Set to ``true`` to enable Pull Request reviews
290291
from clang-tidy.
291292
292293
Defaults to ``%(default)s``.""",
293294
)
294295
cli_arg_parser.add_argument(
296+
"-m",
295297
"--format-review",
296-
"-fr",
297298
default="false",
298299
type=lambda input: input.lower() == "true",
299-
help="""Set to ``true`` to enable PR review suggestions
300+
help="""Set to ``true`` to enable Pull Request reviews
300301
from clang-format.
301302
302303
Defaults to ``%(default)s``.""",

docs/conf.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import re
88
from pathlib import Path
9-
import io
109
from sphinx.application import Sphinx
1110

1211
sys.path.insert(0, str(Path(__file__).parent.parent))
@@ -115,22 +114,26 @@
115114
def setup(app: Sphinx):
116115
"""Generate a doc from the executable script's ``--help`` output."""
117116

118-
with io.StringIO() as help_out:
119-
cli_arg_parser.print_help(help_out)
120-
output = help_out.getvalue()
117+
output = cli_arg_parser.format_help()
121118
first_line = re.search(r"^options:\s*\n", output, re.MULTILINE)
122119
if first_line is None:
123120
raise OSError("unrecognized output from `cpp-linter -h`")
124121
output = output[first_line.end(0) :]
125122
doc = "Command Line Interface Options\n==============================\n\n"
126-
CLI_OPT_NAME = re.compile(r"^\s*(\-\w)\s?\{?[A-Za-z_,]*\}?,\s(\-\-.*?)\s")
123+
doc += ".. note::\n\n These options have a direct relationship with the\n "
124+
doc += "`cpp-linter-action user inputs "
125+
doc += "<https://github.com/cpp-linter/cpp-linter-action#optional-inputs>`_. "
126+
doc += "Although, some default values may differ.\n\n"
127+
CLI_OPT_NAME = re.compile(
128+
r"^\s*(\-[A-Za-z]+)\s?\{?[A-Za-z_,0-9]*\}?,\s(\-\-[^\s]*?)\s"
129+
)
127130
for line in output.splitlines():
128131
match = CLI_OPT_NAME.search(line)
129132
if match is not None:
130133
# print(match.groups())
131134
doc += "\n.. std:option:: " + ", ".join(match.groups()) + "\n\n"
132135
options_match = re.search(
133-
r"\-\w\s\{[a-zA-Z,]+\},\s\-\-[\w\-]+\s\{[a-zA-Z,]+\}", line
136+
r"\-\w\s\{[a-zA-Z,0-9]+\},\s\-\-[\w\-]+\s\{[a-zA-Z,0-9]+\}", line
134137
)
135138
if options_match is not None:
136139
new_txt = options_match.group()

docs/index.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
:hidden:
55

66
self
7-
building_docs
8-
9-
.. toctree::
10-
:hidden:
11-
7+
pr_review_caveats
128
cli_args
139

1410
.. toctree::
@@ -26,8 +22,7 @@
2622
API-Reference/cpp_linter.loggers
2723
API-Reference/cpp_linter.common_fs
2824

29-
Indices and tables
30-
==================
25+
.. toctree::
26+
:hidden:
3127

32-
* :ref:`genindex`
33-
* :ref:`modindex`
28+
building_docs

docs/pr_review_caveats.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Pull Request Review Caveats
2+
===========================
3+
4+
.. _repository settings: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests
5+
.. _organization settings: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests
6+
.. _hiding a comment: https://docs.github.com/en/communities/moderating-comments-and-conversations/managing-disruptive-comments#hiding-a-comment
7+
.. _resolve a conversion: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations
8+
9+
.. hint::
10+
11+
This information is specific to GitHub Pull Requests (often abbreviated as "PR").
12+
13+
While the Pull Request review feature has been thoroughly tested, there are still some caveats to
14+
beware of when using Pull Request reviews.
15+
16+
1. The "GitHub Actions" bot may need to be allowed to approve Pull Requests.
17+
By default, the bot cannot approve Pull Request changes, only request more changes.
18+
This will show as a warning in the workflow logs if the given token (set to the
19+
environment variable ``GITHUB_TOKEN``) isn't configured with the proper permissions.
20+
21+
.. seealso::
22+
23+
Refer to the GitHub documentation for `repository settings`_ or `organization settings`_
24+
about adjusting the required permissions for GitHub Actions's ``secrets.GITHUB_TOKEN``.
25+
2. The feature is auto-disabled for
26+
27+
- closed Pull Requests
28+
- Pull Requests marked as "draft"
29+
- push events
30+
3. Clang-tidy and clang-format suggestions are shown in 1 Pull Request review.
31+
32+
- Users are encouraged to choose either :std:option:`--tidy-review` or :std:option:`--format-review`.
33+
Enabling both will likely show duplicate or similar suggestions.
34+
Remember, clang-tidy can be configured to use the same ``style`` that clang-format accepts.
35+
There is no current implementation to combine suggestions from both tools (clang-tidy kind of
36+
does that anyway).
37+
- Each generated review is specific to the commit that triggered the Continuous Integration
38+
workflow.
39+
- Outdated reviews are dismissed but not marked as resolved.
40+
Also, the outdated review's summary comment is not automatically hidden.
41+
To reduce the Pull Request's thread noise, users interaction is required.
42+
43+
.. seealso::
44+
45+
Refer to GitHub's documentation about `hiding a comment`_.
46+
Hiding a Pull Request review's summary comment will not resolve the suggestions in the diff.
47+
Please also refer to `resolve a conversion`_ to collapse outdated or duplicate suggestions
48+
in the diff.
49+
50+
GitHub REST API does not provide a way to hide comments or mark review suggestions as resolved.
51+
52+
.. tip::
53+
54+
We do support an environment variable named ``CPP_LINTER_PR_REVIEW_SUMMARY_ONLY``.
55+
If the variable is set to ``true``, then the review only contains a summary comment
56+
with no suggestions posted in the diff.
57+
4. If any suggestions did not fit within the Pull Request diff, then the review's summary comment will
58+
indicate how many suggestions were left out.
59+
The full patch of suggestions is always included as a collapsed code block in the review summary
60+
comment. This isn't a problem we can fix.
61+
GitHub won't allow review comments/suggestions to target lines that are not shown in the Pull
62+
Request diff (the summation of file differences in a Pull Request).
63+
64+
- Users are encouraged to set :std:option:`--lines-changed-only` to ``true``.
65+
This will *help* us keep the suggestions limited to lines that are shown within the Pull
66+
Request diff.
67+
However, there are still some cases where clang-format or clang-tidy will apply fixes to lines
68+
that are not within the diff.
69+
This can't be avoided because the ``--line-filter`` passed to the clang-tidy (and ``--lines``
70+
passed to clang-format) only applies to analysis, not fixes.
71+
- Not every diagnostic from clang-tidy can be automatically fixed.
72+
Some diagnostics require user interaction/decision to properly address.
73+
- Some fixes provided might depend on what compiler is used.
74+
We have made it so clang-tidy takes advantage of any fixes provided by the compiler.
75+
Compilation errors may still prevent clang-tidy from reporting all concerns.

0 commit comments

Comments
 (0)