Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions bot/code_review_bot/report/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,34 @@ def publish(self, issues, revision, task_failures, notices, reviewers):
nb_dismissed = self.github_client.cleanup_pr(revision)

if publishable_issues:
messages = [
f"{len(publishable_issues)} issue{'s' if len(publishable_issues) > 1 else ''} "
f"{'have' if len(publishable_issues) > 1 else 'has'} "
"been found in this revision."
]

# Issues that are not in patch cannot be published directly through a Github review
inside_patch_issues = [
issue for issue in publishable_issues if issue.in_patch
]
outside_patch_issues = [
issue for issue in publishable_issues if not issue.in_patch
]
if outside_patch_issues:
# Mention issues outside of the patch in the review main comment, after a new line
messages.append("")
messages.append(
f"{len(outside_patch_issues)} issue{'s' if len(outside_patch_issues) > 1 else ''} "
f"{'are' if len(outside_patch_issues) > 1 else 'is'} located outside of the patch:"
)
for issue in outside_patch_issues:
messages.append(f"* `{issue.path}:{issue.line}` {issue.as_text()}")

# Publish a review summarizing detected, unresolved and closed issues
self.github_client.publish_review(
issues=publishable_issues,
issues=inside_patch_issues,
revision=revision,
message=f"{len(publishable_issues)} issues have been found in this revision",
message="\n".join(messages),
event=ReviewEvent.RequestChanges,
)
else:
Expand Down
23 changes: 17 additions & 6 deletions bot/tests/test_reporter_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import json
from pathlib import Path
from textwrap import dedent

import responses
from conftest import FIXTURES_DIR
Expand Down Expand Up @@ -57,6 +58,7 @@ def test_github_review(
"modernize-use-nullptr",
"dummy message",
)
assert issue_clang_tidy.in_patch is True
assert issue_clang_tidy.is_publishable()

issue_coverage = CoverageIssue(
Expand All @@ -66,8 +68,16 @@ def test_github_review(
"This file is uncovered",
revision,
)
assert issue_coverage.in_patch is False
assert issue_coverage.is_publishable()

# Mock to publish a comment, regarding issues outside of the patch
responses.add(
responses.POST,
"https://api.github.com:443/repos/owner/repo-name/pulls/1/comments",
json={},
)

# Mock to publish a new review
responses.add(
responses.POST,
Expand Down Expand Up @@ -110,20 +120,21 @@ def test_github_review(
),
("POST", "https://api.github.com:443/repos/owner/repo-name/pulls/1/reviews"),
]

review_creation = responses.calls[-1]
assert json.loads(review_creation.request.body) == {
"body": "2 issues have been found in this revision",
"body": dedent("""
2 issues have been found in this revision.

1 issue is located outside of the patch:
* `path/to/test.cpp:1` This file is uncovered
""").strip(),
"comments": [
{
"body": "dummy message",
"path": "another_test.cpp",
"line": 42,
},
{
"body": "This file is uncovered",
"path": "path/to/test.cpp",
"line": 1,
},
],
"commit_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"event": "REQUEST_CHANGES",
Expand Down