55# file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
77from github import Auth , GithubIntegration
8+ from github .PullRequest import ReviewComment
9+
10+ from code_review_bot import Issue
11+ from code_review_bot .revisions .base import Revision
812
913
1014class GithubClient :
@@ -28,17 +32,25 @@ def __init__(self, client_id: str, pem_key_path: str, installation_id: str):
2832 # setup API
2933 self .api = self .installation .get_github_for_installation ()
3034
31- def comment (
32- self ,
33- * ,
34- revision , # GithubRevision
35- issue ,
36- ):
37- repo = self .api .get_repo (revision .repository )
38- pull_request = repo .get_pull (revision .pull_id )
39- pull_request .create_comment (
40- commit = revision .commit ,
35+ self .review_comments = []
36+
37+ def _build_review_comment (self , issue ):
38+ return ReviewComment (
4139 path = issue .path ,
4240 position = issue .line ,
4341 body = issue .message ,
4442 )
43+
44+ def publish_review (self , issues : list [Issue ], revision : Revision , message : str ):
45+ """
46+ Publish a review from a list of publishable issues, requesting changes to the author.
47+ """
48+ repo = self .api .get_repo (revision .repository )
49+ pull_request = repo .get_pull (revision .pull_id )
50+ pull_request .create_review (
51+ commit = repo .get_commit (revision .commit ),
52+ body = message ,
53+ comments = [self ._build_review_comment (issue ) for issue in issues ],
54+ # https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request
55+ event = "REQUEST_CHANGES" ,
56+ )
0 commit comments