File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22# License, v. 2.0. If a copy of the MPL was not distributed with this
33# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
5+ from urllib .parse import urlparse
6+
57import requests
68import structlog
79
@@ -32,6 +34,13 @@ def __str__(self):
3234 def __repr__ (self ):
3335 return f"GithubRevision repo_url={ self .repo_url } branch={ self .branch } pull_number={ self .pull_number } sha={ self .pull_head_sha } "
3436
37+ @property
38+ def repo_name (self ):
39+ """
40+ Extract the name of the repository from its URL
41+ """
42+ return urlparse (self .repo_url ).path .strip ("/" )
43+
3544 def load_patch (self ):
3645 """
3746 Load the patch content for the current pull request HEAD
Original file line number Diff line number Diff line change 88from github .PullRequest import ReviewComment
99
1010from code_review_bot import Issue
11- from code_review_bot .revisions . base import Revision
11+ from code_review_bot .revisions import GithubRevision
1212
1313
1414class GithubClient :
@@ -41,14 +41,16 @@ def _build_review_comment(self, issue):
4141 body = issue .message ,
4242 )
4343
44- def publish_review (self , issues : list [Issue ], revision : Revision , message : str ):
44+ def publish_review (
45+ self , issues : list [Issue ], revision : GithubRevision , message : str
46+ ):
4547 """
4648 Publish a review from a list of publishable issues, requesting changes to the author.
4749 """
48- repo = self .api .get_repo (revision .repository )
49- pull_request = repo .get_pull (revision .pull_id )
50+ repo = self .api .get_repo (revision .repo_name )
51+ pull_request = repo .get_pull (revision .pull_number )
5052 pull_request .create_review (
51- commit = repo .get_commit (revision .commit ),
53+ commit = repo .get_commit (revision .pull_head_sha ),
5254 body = message ,
5355 comments = [self ._build_review_comment (issue ) for issue in issues ],
5456 # https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request
Original file line number Diff line number Diff line change 22import sys
33
44from code_review_bot .report .github import GithubReporter
5- from code_review_bot .revisions . base import Revision
5+ from code_review_bot .revisions import GithubRevision
66from code_review_bot .tasks .clang_tidy import ClangTidyIssue , ClangTidyTask
77
88
@@ -52,12 +52,12 @@ def main():
5252 Initialize a Github reporter and publish issues
5353 """
5454 reporter = GithubReporter (get_configuration ())
55- revision = Revision ()
56-
57- # Add the attributes that will be supported by GithubRevision
58- revision . repository = "vrigal/test-dev-mozilla"
59- revision . commit = "da4ed2eccaff01034c1c2091d2797d55bc0c57cf"
60- revision . pull_id = 3
55+ revision = GithubRevision (
56+ repo_url = "https://github.com/vrigal/test-dev-mozilla" ,
57+ branch = "reporter-demo" ,
58+ pull_head_sha = "da4ed2eccaff01034c1c2091d2797d55bc0c57cf" ,
59+ pull_number = 3 ,
60+ )
6161
6262 analyzer = mock_task (ClangTidyTask , "source-test-clang-tidy" )
6363 issue1 = ClangTidyIssue (
You can’t perform that action at this time.
0 commit comments