Skip to content

Commit d3c27fa

Browse files
committed
allow PR reviews to be passive
ref cpp-linter/cpp-linter-action#243
1 parent 5458867 commit d3c27fa

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

cpp_linter/cli.py

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class Args(UserDict):
6767
ignore_tidy: str = ""
6868
#: See :std:option:`--ignore-format`.
6969
ignore_format: str = ""
70+
#: See :std:option:`--passive-reviews`.
71+
passive_reviews: bool = False
7072

7173

7274
_parser_args: Dict[Sequence[str], Any] = {}
@@ -343,6 +345,12 @@ class Args(UserDict):
343345
344346
Defaults to ``%(default)s``.""",
345347
)
348+
_parser_args[("-R", "--passive-reviews")] = dict(
349+
default="false",
350+
type=lambda input: input.lower() == "true",
351+
help="""Set to ``true`` to prevent Pull Request
352+
reviews from requesting or approving changes.""",
353+
)
346354

347355

348356
def _parse_jobs(val: str) -> Optional[int]:

cpp_linter/rest_api/github_api.py

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def post_feedback(
212212
tidy_review=args.tidy_review,
213213
format_review=args.format_review,
214214
no_lgtm=args.no_lgtm,
215+
passive_reviews=args.passive_reviews,
215216
)
216217

217218
def make_annotations(
@@ -346,6 +347,7 @@ def post_review(
346347
tidy_review: bool,
347348
format_review: bool,
348349
no_lgtm: bool,
350+
passive_reviews: bool,
349351
):
350352
url = f"{self.api_url}/repos/{self.repo}/pulls/{self.pull_request}"
351353
response = self.api_request(url=url)
@@ -393,6 +395,8 @@ def post_review(
393395
return
394396
body += "\nGreat job! :tada:"
395397
event = "APPROVE"
398+
if passive_reviews:
399+
event = "COMMENT"
396400
body += USER_OUTREACH
397401
payload = {
398402
"body": body,

tests/reviews/test_pr_review.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
summary_only=False,
3030
no_lgtm=False,
3131
num_workers=None,
32+
is_passive=False,
3233
)
3334

3435

@@ -56,6 +57,7 @@ def mk_param_set(**kwargs) -> OrderedDict:
5657
tuple(mk_param_set(tidy_review=True, changes=1).values()),
5758
tuple(mk_param_set(tidy_review=True, changes=0).values()),
5859
tuple(mk_param_set(tidy_review=True, changes=0, summary_only=True).values()),
60+
tuple(mk_param_set(is_passive=True).values()),
5961
],
6062
ids=[
6163
"draft",
@@ -68,6 +70,7 @@ def mk_param_set(**kwargs) -> OrderedDict:
6870
"lines_added",
6971
"all_lines",
7072
"summary_only",
73+
"passive",
7174
],
7275
)
7376
def test_post_review(
@@ -83,6 +86,7 @@ def test_post_review(
8386
summary_only: bool,
8487
no_lgtm: bool,
8588
num_workers: int,
89+
is_passive: bool,
8690
):
8791
"""A mock test of posting PR reviews"""
8892
# patch env vars
@@ -162,6 +166,7 @@ def test_post_review(
162166
args.thread_comments = "false"
163167
args.no_lgtm = no_lgtm
164168
args.file_annotations = False
169+
args.passive_reviews = is_passive
165170

166171
capture_clang_tools_output(files, args=args)
167172
if not force_approved:
@@ -211,7 +216,10 @@ def test_post_review(
211216
if force_approved:
212217
assert json_payload["event"] == "APPROVE"
213218
else:
214-
assert json_payload["event"] == "REQUEST_CHANGES"
219+
if is_passive:
220+
assert json_payload["event"] == "COMMENT"
221+
else:
222+
assert json_payload["event"] == "REQUEST_CHANGES"
215223

216224
# save the body of the review json for manual inspection
217225
assert hasattr(last_request, "text")

0 commit comments

Comments
 (0)