Skip to content

Commit

Permalink
Add option to edit LGTM message and to turn it off
Browse files Browse the repository at this point in the history
  • Loading branch information
bwrsandman committed Aug 2, 2022
1 parent 6160d7d commit 3023eb5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ at once, so `clang-tidy-review` will only attempt to post the first
- default: ''
- `max_comments`: Maximum number of comments to post at once
- default: '25'
- `lgtm_comment_body`: Message to post on PR if no issues are found. An empty string will post no LGTM comment.
- default: 'clang-tidy review says "All clean, LGTM! :+1:"'

## Outputs

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ inputs:
description: 'Maximum number of comments to post at once'
required: false
default: '25'
lgtm_comment_body:
description: 'Message to post on PR if no issues are found. An empty string will post no LGTM comment.'
required: false
default: 'clang-tidy review says "All clean, LGTM! :+1:"'
pr:
default: ${{ github.event.pull_request.number }}
repo:
Expand All @@ -72,3 +76,4 @@ runs:
- --exclude='${{ inputs.exclude }}'
- --apt-packages=${{ inputs.apt_packages }}
- --cmake-command='${{ inputs.cmake_command }}'
- --lgtm-comment-body='${{ inputs.lgtm_comment_body }}'
21 changes: 15 additions & 6 deletions review.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,20 @@ def get_element(
None,
)

def post_lgtm_comment(self):
def post_lgtm_comment(self, body: str):
"""Post a "LGTM" comment if everything's clean, making sure not to spam"""

BODY = 'clang-tidy review says "All clean, LGTM! :+1:"'
if not body:
return

comments = self.get_pr_comments()

for comment in comments:
if comment["body"] == BODY:
if comment["body"] == body:
print("Already posted, no need to update")
return

self._pull_request.create_issue_comment(BODY)
self._pull_request.create_issue_comment(body)

def post_review(self, review):
"""Submit a completed review"""
Expand Down Expand Up @@ -627,6 +628,7 @@ def main(
include,
exclude,
max_comments,
lgtm_comment_body,
dry_run: bool = False,
):

Expand Down Expand Up @@ -669,7 +671,7 @@ def main(
if clang_tidy_warnings == {}:
print("No warnings, LGTM!")
if not dry_run:
pull_request.post_lgtm_comment()
pull_request.post_lgtm_comment(lgtm_comment_body)
return

diff_lookup = make_file_line_lookup(diff)
Expand All @@ -687,7 +689,7 @@ def main(
if review["comments"] == []:
print("No warnings to report, LGTM!")
if not dry_run:
pull_request.post_lgtm_comment()
pull_request.post_lgtm_comment(lgtm_comment_body)
return

print(f"::set-output name=total_comments::{len(review['comments'])}")
Expand Down Expand Up @@ -804,6 +806,12 @@ def fix_absolute_paths(build_compile_commands, base_dir):
type=int,
default=25,
)
parser.add_argument(
"--lgtm-comment-body",
help="Message to post on PR if no issues are found. An empty string will post no LGTM comment.",
type=str,
default='clang-tidy review says "All clean, LGTM! :+1:"',
)
parser.add_argument("--token", help="github auth token")
parser.add_argument(
"--dry-run", help="Run and generate review, but don't post", action="store_true"
Expand Down Expand Up @@ -849,5 +857,6 @@ def fix_absolute_paths(build_compile_commands, base_dir):
include=include,
exclude=exclude,
max_comments=args.max_comments,
lgtm_comment_body=strip_enclosing_quotes(args.lgtm_comment_body),
dry_run=args.dry_run,
)

0 comments on commit 3023eb5

Please sign in to comment.