-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcode_review.py
32 lines (25 loc) · 1.12 KB
/
code_review.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from codedog.actors.reporters.base import Reporter
from codedog.localization import Localization
from codedog.models.code_review import CodeReview
class CodeReviewMarkdownReporter(Reporter, Localization):
def __init__(self, code_reviews: list[CodeReview], language="en"):
self._code_reviews: list[CodeReview] = code_reviews
self._markdown: str = ""
super().__init__(language=language)
def report(self) -> str:
if not self._markdown:
self._markdown = self._generate_report()
return self._markdown
def _generate_report(self):
code_review_segs = []
for code_review in self._code_reviews:
code_review_segs.append(
self.template.REPORT_CODE_REVIEW_SEGMENT.format(
full_name=code_review.file.full_name,
url=code_review.file.diff_url,
review=code_review.review,
)
)
return self.template.REPORT_CODE_REVIEW.format(
feedback="\n".join(code_review_segs) if code_review_segs else self.template.REPORT_CODE_REVIEW_NO_FEEDBACK,
)