19
19
import zipfile
20
20
from operator import itemgetter
21
21
from pathlib import Path
22
- from typing import Dict , List , Optional , TypedDict
22
+ from typing import Any , Dict , List , Optional , TypedDict
23
23
24
24
import unidiff
25
25
import urllib3
26
26
import yaml
27
27
from github import Auth , Github
28
28
from github .PaginatedList import PaginatedList
29
+ from github .PullRequest import ReviewComment
29
30
from github .Requester import Requester
30
31
from github .WorkflowRun import WorkflowRun
31
32
@@ -46,20 +47,10 @@ class Metadata(TypedDict):
46
47
pr_number : int
47
48
48
49
49
- class PRReviewComment (TypedDict ):
50
- path : str
51
- position : Optional [int ]
52
- body : str
53
- line : Optional [int ]
54
- side : Optional [str ]
55
- start_line : Optional [int ]
56
- start_side : Optional [str ]
57
-
58
-
59
50
class PRReview (TypedDict ):
60
51
body : str
61
52
event : str
62
- comments : List [ PRReviewComment ]
53
+ comments : list [ ReviewComment ]
63
54
64
55
65
56
class HashableComment :
@@ -125,7 +116,7 @@ def add_auth_arguments(parser: argparse.ArgumentParser):
125
116
group_app .add_argument ("--installation-id" , type = int , help = "app installation ID" )
126
117
127
118
128
- def get_auth_from_arguments (args : argparse .Namespace ) -> Auth :
119
+ def get_auth_from_arguments (args : argparse .Namespace ) -> Auth . Auth :
129
120
if args .token :
130
121
return Auth .Token (args .token )
131
122
@@ -260,7 +251,7 @@ def load_clang_tidy_warnings():
260
251
class PullRequest :
261
252
"""Add some convenience functions not in PyGithub"""
262
253
263
- def __init__ (self , repo : str , pr_number : Optional [int ], auth : Auth ) -> None :
254
+ def __init__ (self , repo : str , pr_number : Optional [int ], auth : Auth . Auth ) -> None :
264
255
self .repo_name = repo
265
256
self .pr_number = pr_number
266
257
self .auth = auth
@@ -539,7 +530,7 @@ def replace_one_line(replacement_set, line_num, offset_lookup):
539
530
line_offset = offset_lookup [filename ][line_num ]
540
531
541
532
# List of (start, end) offsets from line_offset
542
- insert_offsets = [(0 , 0 )]
533
+ insert_offsets : list [ tuple [ Optional [ int ], Optional [ int ]]] = [(0 , 0 )]
543
534
# Read all the source lines into a dict so we only get one copy of
544
535
# each line, though we might read the same line in multiple times
545
536
source_lines = {}
@@ -755,7 +746,7 @@ def create_review_file(
755
746
if "Diagnostics" not in clang_tidy_warnings :
756
747
return None
757
748
758
- comments : List [PRReviewComment ] = []
749
+ comments : List [ReviewComment ] = []
759
750
760
751
for diagnostic in clang_tidy_warnings ["Diagnostics" ]:
761
752
try :
@@ -1227,7 +1218,7 @@ def decorate_check_names(comment: str) -> str:
1227
1218
return re .sub (regex , subst , comment , count = 1 , flags = re .MULTILINE )
1228
1219
1229
1220
1230
- def decorate_comment (comment : PRReviewComment ) -> PRReviewComment :
1221
+ def decorate_comment (comment : ReviewComment ) -> ReviewComment :
1231
1222
comment ["body" ] = decorate_check_names (comment ["body" ])
1232
1223
return comment
1233
1224
@@ -1288,10 +1279,12 @@ def convert_comment_to_annotations(comment):
1288
1279
}
1289
1280
1290
1281
1291
- def post_annotations (pull_request : PullRequest , review : Optional [PRReview ]) -> int :
1282
+ def post_annotations (
1283
+ pull_request : PullRequest , review : Optional [PRReview ]
1284
+ ) -> Optional [int ]:
1292
1285
"""Post the first 10 comments in the review as annotations"""
1293
1286
1294
- body = {
1287
+ body : dict [ str , Any ] = {
1295
1288
"name" : "clang-tidy-review" ,
1296
1289
"head_sha" : pull_request .pull_request .head .sha ,
1297
1290
"status" : "completed" ,
@@ -1309,7 +1302,7 @@ def post_annotations(pull_request: PullRequest, review: Optional[PRReview]) -> i
1309
1302
for comment in review ["comments" ]:
1310
1303
first_line = comment ["body" ].splitlines ()[0 ]
1311
1304
comments .append (
1312
- f"{ comment ['path' ]} :{ comment .get ('start_line' , comment [ 'line' ] )} : { first_line } "
1305
+ f"{ comment ['path' ]} :{ comment .get ('start_line' , comment . get ( 'line' , 0 ) )} : { first_line } "
1313
1306
)
1314
1307
1315
1308
total_comments = len (review ["comments" ])
0 commit comments