11import logging
22from datetime import datetime
3- from typing import List , Optional
3+ from typing import Any , Dict , List , Optional
44
55import shared .rate_limits as rate_limits
66import yaml
99from graphql .type .definition import GraphQLResolveInfo
1010
1111from codecov .db import sync_to_async
12- from codecov_auth .models import SERVICE_GITHUB , SERVICE_GITHUB_ENTERPRISE
13- from core .models import Branch , Repository
12+ from codecov_auth .models import SERVICE_GITHUB , SERVICE_GITHUB_ENTERPRISE , Owner
13+ from core .models import Branch , Commit , Pull , Repository
1414from graphql_api .actions .commits import repo_commits
1515from graphql_api .dataloader .commit import CommitLoader
1616from graphql_api .dataloader .owner import OwnerLoader
2121 CoverageAnalyticsProps ,
2222)
2323from graphql_api .types .enums import OrderingDirection
24+ from graphql_api .types .enums .enum_types import PullRequestState
2425from graphql_api .types .errors .errors import NotFoundError , OwnerNotActivatedError
2526from services .profiling import CriticalFile , ProfilingSummary
2627from services .redis_configuration import get_redis_connection
@@ -59,18 +60,18 @@ def resolve_branch(
5960
6061
6162@repository_bindable .field ("author" )
62- def resolve_author (repository : Repository , info : GraphQLResolveInfo ):
63+ def resolve_author (repository : Repository , info : GraphQLResolveInfo ) -> Owner :
6364 return OwnerLoader .loader (info ).load (repository .author_id )
6465
6566
6667@repository_bindable .field ("commit" )
67- def resolve_commit (repository : Repository , info : GraphQLResolveInfo , id ) :
68+ def resolve_commit (repository : Repository , info : GraphQLResolveInfo , id : int ) -> Commit :
6869 loader = CommitLoader .loader (info , repository .pk )
6970 return loader .load (id )
7071
7172
7273@repository_bindable .field ("uploadToken" )
73- def resolve_upload_token (repository : Repository , info : GraphQLResolveInfo ):
74+ def resolve_upload_token (repository : Repository , info : GraphQLResolveInfo ) -> str :
7475 should_hide_tokens = settings .HIDE_ALL_CODECOV_TOKENS
7576
7677 current_owner = info .context ["request" ].current_owner
@@ -86,7 +87,7 @@ def resolve_upload_token(repository: Repository, info: GraphQLResolveInfo):
8687
8788
8889@repository_bindable .field ("pull" )
89- def resolve_pull (repository : Repository , info : GraphQLResolveInfo , id ) :
90+ def resolve_pull (repository : Repository , info : GraphQLResolveInfo , id : int ) -> Pull :
9091 command = info .context ["executor" ].get_command ("pull" )
9192 return command .fetch_pull_request (repository , id )
9293
@@ -95,10 +96,10 @@ def resolve_pull(repository: Repository, info: GraphQLResolveInfo, id):
9596async def resolve_pulls (
9697 repository : Repository ,
9798 info : GraphQLResolveInfo ,
98- filters = None ,
99- ordering_direction = OrderingDirection .DESC ,
100- ** kwargs ,
101- ):
99+ filters : Optional [ Dict [ str , List [ PullRequestState ]]] = None ,
100+ ordering_direction : Optional [ OrderingDirection ] = OrderingDirection .DESC ,
101+ ** kwargs : Any ,
102+ ) -> List [ Pull ] :
102103 command = info .context ["executor" ].get_command ("pull" )
103104 queryset = await command .fetch_pull_requests (repository , filters )
104105 return await queryset_to_connection (
@@ -111,8 +112,11 @@ async def resolve_pulls(
111112
112113@repository_bindable .field ("commits" )
113114async def resolve_commits (
114- repository : Repository , info : GraphQLResolveInfo , filters = None , ** kwargs
115- ):
115+ repository : Repository ,
116+ info : GraphQLResolveInfo ,
117+ filters : Optional [Dict [str , Any ]] = None ,
118+ ** kwargs : Any ,
119+ ) -> List [Commit ]:
116120 queryset = await sync_to_async (repo_commits )(repository , filters )
117121 connection = await queryset_to_connection (
118122 queryset ,
@@ -132,8 +136,11 @@ async def resolve_commits(
132136
133137@repository_bindable .field ("branches" )
134138async def resolve_branches (
135- repository : Repository , info : GraphQLResolveInfo , filters = None , ** kwargs
136- ):
139+ repository : Repository ,
140+ info : GraphQLResolveInfo ,
141+ filters : Optional [Dict [str , str | bool ]] = None ,
142+ ** kwargs : Any ,
143+ ) -> List [Branch ]:
137144 command = info .context ["executor" ].get_command ("branch" )
138145 queryset = await command .fetch_branches (repository , filters )
139146 return await queryset_to_connection (
@@ -145,18 +152,20 @@ async def resolve_branches(
145152
146153
147154@repository_bindable .field ("defaultBranch" )
148- def resolve_default_branch (repository : Repository , info : GraphQLResolveInfo ):
155+ def resolve_default_branch (repository : Repository , info : GraphQLResolveInfo ) -> str :
149156 return repository .branch
150157
151158
152159@repository_bindable .field ("profilingToken" )
153- def resolve_profiling_token (repository : Repository , info : GraphQLResolveInfo ):
160+ def resolve_profiling_token (repository : Repository , info : GraphQLResolveInfo ) -> str :
154161 command = info .context ["executor" ].get_command ("repository" )
155162 return command .get_repository_token (repository , token_type = "profiling" )
156163
157164
158165@repository_bindable .field ("staticAnalysisToken" )
159- def resolve_static_analysis_token (repository : Repository , info : GraphQLResolveInfo ):
166+ def resolve_static_analysis_token (
167+ repository : Repository , info : GraphQLResolveInfo
168+ ) -> str :
160169 command = info .context ["executor" ].get_command ("repository" )
161170 return command .get_repository_token (repository , token_type = "static_analysis" )
162171
@@ -178,20 +187,24 @@ def resolve_critical_files(
178187
179188
180189@repository_bindable .field ("graphToken" )
181- def resolve_graph_token (repository : Repository , info : GraphQLResolveInfo ):
190+ def resolve_graph_token (repository : Repository , info : GraphQLResolveInfo ) -> str :
182191 return repository .image_token
183192
184193
185194@repository_bindable .field ("yaml" )
186- def resolve_repo_yaml (repository : Repository , info : GraphQLResolveInfo ):
195+ def resolve_repo_yaml (
196+ repository : Repository , info : GraphQLResolveInfo
197+ ) -> Optional [str ]:
187198 if repository .yaml is None :
188199 return None
189200 return yaml .dump (repository .yaml )
190201
191202
192203@repository_bindable .field ("bot" )
193204@sync_to_async
194- def resolve_repo_bot (repository : Repository , info : GraphQLResolveInfo ):
205+ def resolve_repo_bot (
206+ repository : Repository , info : GraphQLResolveInfo
207+ ) -> Optional [Owner ]:
195208 return repository .bot
196209
197210
@@ -212,7 +225,9 @@ def resolve_is_ats_configured(repository: Repository, info: GraphQLResolveInfo)
212225
213226
214227@repository_bindable .field ("repositoryConfig" )
215- def resolve_repository_config (repository : Repository , info : GraphQLResolveInfo ):
228+ def resolve_repository_config (
229+ repository : Repository , info : GraphQLResolveInfo
230+ ) -> Repository :
216231 return repository
217232
218233
@@ -251,7 +266,7 @@ def resolve_coverage_enabled(
251266
252267
253268@repository_result_bindable .type_resolver
254- def resolve_repository_result_type (obj , * _ ) :
269+ def resolve_repository_result_type (obj : Any , * _ : Any ) -> Optional [ str ] :
255270 if isinstance (obj , Repository ):
256271 return "Repository"
257272 elif isinstance (obj , OwnerNotActivatedError ):
@@ -262,7 +277,9 @@ def resolve_repository_result_type(obj, *_):
262277
263278@repository_bindable .field ("isFirstPullRequest" )
264279@sync_to_async
265- def resolve_is_first_pull_request (repository : Repository , info ) -> bool :
280+ def resolve_is_first_pull_request (
281+ repository : Repository , info : GraphQLResolveInfo
282+ ) -> bool :
266283 has_one_pr = repository .pull_requests .count () == 1
267284
268285 if has_one_pr :
@@ -274,7 +291,9 @@ def resolve_is_first_pull_request(repository: Repository, info) -> bool:
274291
275292@repository_bindable .field ("isGithubRateLimited" )
276293@sync_to_async
277- def resolve_is_github_rate_limited (repository : Repository , info ) -> bool | None :
294+ def resolve_is_github_rate_limited (
295+ repository : Repository , info : GraphQLResolveInfo
296+ ) -> bool | None :
278297 if (
279298 repository .service != SERVICE_GITHUB
280299 and repository .service != SERVICE_GITHUB_ENTERPRISE
0 commit comments