Skip to content

Commit 005b25e

Browse files
committed
Remove reuse_review_comments functionality.
1 parent 3b3cf1a commit 005b25e

File tree

1 file changed

+43
-54
lines changed

1 file changed

+43
-54
lines changed

cpp_linter/rest_api/github_api.py

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ def post_feedback(
334334
passive_reviews=args.passive_reviews,
335335
clang_versions=clang_versions,
336336
delete_review_comments=args.delete_review_comments,
337-
reuse_review_comments=args.reuse_review_comments,
338337
)
339338

340339
def make_annotations(
@@ -472,7 +471,6 @@ def post_review(
472471
passive_reviews: bool,
473472
clang_versions: ClangVersions,
474473
delete_review_comments: bool = True,
475-
reuse_review_comments: bool = True,
476474
):
477475
url = f"{self.api_url}/repos/{self.repo}/pulls/{self.pull_request}"
478476
response = self.api_request(url=url)
@@ -507,7 +505,7 @@ def post_review(
507505
ignored_reviews = []
508506
if not summary_only:
509507
ignored_reviews = self._check_reused_comments(
510-
delete_review_comments, reuse_review_comments, review_comments
508+
delete_review_comments, review_comments
511509
)
512510
self._hide_stale_reviews(ignored_reviews=ignored_reviews)
513511
if len(review_comments.suggestions) == 0 and len(ignored_reviews) > 0:
@@ -727,66 +725,57 @@ def _hide_stale_reviews(self, ignored_reviews: List[str]):
727725
def _check_reused_comments(
728726
self,
729727
delete_review_comments: bool,
730-
reuse_review_comments: bool,
731728
review_comments: ReviewComments,
732729
) -> List[str]:
733730
ignored_reviews = []
734731
found_threads = self._get_existing_review_comments(
735-
no_dismissed=reuse_review_comments and not delete_review_comments
732+
no_dismissed=not delete_review_comments
736733
)
737734
if found_threads:
738-
if reuse_review_comments:
739-
# Keep already posted comments if they match new ones
740-
existing_review_comments = []
741-
for thread in found_threads:
742-
for comment in thread["comments"]["nodes"]:
743-
found = False
744-
if "originalLine" not in comment:
745-
raise ValueError(
746-
"GraphQL response malformed: 'originalLine' missing in comment"
747-
)
748-
line_start = (
749-
comment.get("startLine", None)
750-
or comment.get("originalStartLine", None)
751-
or -1
735+
# Keep already posted comments if they match new ones
736+
existing_review_comments = []
737+
for thread in found_threads:
738+
for comment in thread["comments"]["nodes"]:
739+
found = False
740+
if "originalLine" not in comment:
741+
raise ValueError(
742+
"GraphQL response malformed: 'originalLine' missing in comment"
752743
)
753-
line_end = comment.get("line", None) or comment["originalLine"]
754-
for suggestion in review_comments.suggestions:
755-
if (
756-
suggestion.file_name == comment["path"]
757-
and suggestion.line_start == line_start
758-
and suggestion.line_end == line_end
759-
and f"{COMMENT_MARKER}{suggestion.comment}"
760-
== comment["body"]
761-
and suggestion not in existing_review_comments
762-
and thread["isResolved"] is False
763-
and thread["isCollapsed"] is False
764-
and comment["pullRequestReview"]["isMinimized"] is False
765-
):
766-
found = True
767-
logger.info(
768-
"Using existing review comment: path='%s', line_start='%s', line_end='%s'",
769-
comment["path"],
770-
line_start,
771-
line_end,
772-
)
773-
ignored_reviews.append(
774-
comment["pullRequestReview"]["id"]
775-
)
776-
existing_review_comments.append(suggestion)
777-
break
778-
if not found:
779-
self._close_review_comment(
780-
thread["id"], comment["id"], delete_review_comments
744+
line_start = (
745+
comment.get("startLine", None)
746+
or comment.get("originalStartLine", None)
747+
or -1
748+
)
749+
line_end = comment.get("line", None) or comment["originalLine"]
750+
for suggestion in review_comments.suggestions:
751+
if (
752+
suggestion.file_name == comment["path"]
753+
and suggestion.line_start == line_start
754+
and suggestion.line_end == line_end
755+
and f"{COMMENT_MARKER}{suggestion.comment}"
756+
== comment["body"]
757+
and suggestion not in existing_review_comments
758+
and thread["isResolved"] is False
759+
and thread["isCollapsed"] is False
760+
and comment["pullRequestReview"]["isMinimized"] is False
761+
):
762+
found = True
763+
logger.info(
764+
"Using existing review comment: path='%s', line_start='%s', line_end='%s'",
765+
comment["path"],
766+
line_start,
767+
line_end,
781768
)
782-
review_comments.remove_reused_suggestions(
783-
existing_review_comments=existing_review_comments
784-
)
785-
else:
786-
# Not reusing so close all existing review comments
787-
for thread in found_threads:
788-
for comment in thread["comments"]["nodes"]:
769+
ignored_reviews.append(
770+
comment["pullRequestReview"]["id"]
771+
)
772+
existing_review_comments.append(suggestion)
773+
break
774+
if not found:
789775
self._close_review_comment(
790776
thread["id"], comment["id"], delete_review_comments
791777
)
778+
review_comments.remove_reused_suggestions(
779+
existing_review_comments=existing_review_comments
780+
)
792781
return ignored_reviews

0 commit comments

Comments
 (0)