Skip to content

Commit 87a563c

Browse files
committed
fix: correct various types
1 parent 5e9fb02 commit 87a563c

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

post/clang_tidy_review/clang_tidy_review/__init__.py

+13-20
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
import zipfile
2020
from operator import itemgetter
2121
from pathlib import Path
22-
from typing import Dict, List, Optional, TypedDict
22+
from typing import Any, Dict, List, Optional, TypedDict
2323

2424
import unidiff
2525
import urllib3
2626
import yaml
2727
from github import Auth, Github
2828
from github.PaginatedList import PaginatedList
29+
from github.PullRequest import ReviewComment
2930
from github.Requester import Requester
3031
from github.WorkflowRun import WorkflowRun
3132

@@ -46,20 +47,10 @@ class Metadata(TypedDict):
4647
pr_number: int
4748

4849

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-
5950
class PRReview(TypedDict):
6051
body: str
6152
event: str
62-
comments: List[PRReviewComment]
53+
comments: list[ReviewComment]
6354

6455

6556
class HashableComment:
@@ -125,7 +116,7 @@ def add_auth_arguments(parser: argparse.ArgumentParser):
125116
group_app.add_argument("--installation-id", type=int, help="app installation ID")
126117

127118

128-
def get_auth_from_arguments(args: argparse.Namespace) -> Auth:
119+
def get_auth_from_arguments(args: argparse.Namespace) -> Auth.Auth:
129120
if args.token:
130121
return Auth.Token(args.token)
131122

@@ -260,7 +251,7 @@ def load_clang_tidy_warnings():
260251
class PullRequest:
261252
"""Add some convenience functions not in PyGithub"""
262253

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:
264255
self.repo_name = repo
265256
self.pr_number = pr_number
266257
self.auth = auth
@@ -539,7 +530,7 @@ def replace_one_line(replacement_set, line_num, offset_lookup):
539530
line_offset = offset_lookup[filename][line_num]
540531

541532
# List of (start, end) offsets from line_offset
542-
insert_offsets = [(0, 0)]
533+
insert_offsets: list[tuple[Optional[int], Optional[int]]] = [(0, 0)]
543534
# Read all the source lines into a dict so we only get one copy of
544535
# each line, though we might read the same line in multiple times
545536
source_lines = {}
@@ -755,7 +746,7 @@ def create_review_file(
755746
if "Diagnostics" not in clang_tidy_warnings:
756747
return None
757748

758-
comments: List[PRReviewComment] = []
749+
comments: List[ReviewComment] = []
759750

760751
for diagnostic in clang_tidy_warnings["Diagnostics"]:
761752
try:
@@ -1227,7 +1218,7 @@ def decorate_check_names(comment: str) -> str:
12271218
return re.sub(regex, subst, comment, count=1, flags=re.MULTILINE)
12281219

12291220

1230-
def decorate_comment(comment: PRReviewComment) -> PRReviewComment:
1221+
def decorate_comment(comment: ReviewComment) -> ReviewComment:
12311222
comment["body"] = decorate_check_names(comment["body"])
12321223
return comment
12331224

@@ -1288,10 +1279,12 @@ def convert_comment_to_annotations(comment):
12881279
}
12891280

12901281

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]:
12921285
"""Post the first 10 comments in the review as annotations"""
12931286

1294-
body = {
1287+
body: dict[str, Any] = {
12951288
"name": "clang-tidy-review",
12961289
"head_sha": pull_request.pull_request.head.sha,
12971290
"status": "completed",
@@ -1309,7 +1302,7 @@ def post_annotations(pull_request: PullRequest, review: Optional[PRReview]) -> i
13091302
for comment in review["comments"]:
13101303
first_line = comment["body"].splitlines()[0]
13111304
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}"
13131306
)
13141307

13151308
total_comments = len(review["comments"])

post/clang_tidy_review/clang_tidy_review/post.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def main() -> int:
105105
pull_request, review, args.max_comments, lgtm_comment_body, args.dry_run
106106
)
107107

108-
return exit_code if args.num_comments_as_exitcode else 0
108+
return (exit_code or 0) if args.num_comments_as_exitcode else 0
109109

110110

111111
if __name__ == "__main__":

post/clang_tidy_review/clang_tidy_review/review.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def main():
164164

165165
if args.split_workflow:
166166
total_comments = 0 if review is None else len(review["comments"])
167-
set_output("total_comments", total_comments)
167+
set_output("total_comments", str(total_comments))
168168
print("split_workflow is enabled, not posting review")
169169
return
170170

0 commit comments

Comments
 (0)