Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit ba7e350

Browse files
committed
add typing 1
1 parent b29155b commit ba7e350

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import html
2+
from typing import Optional
23

34
import yaml
45
from shared.validation.exceptions import InvalidYamlException
@@ -17,21 +18,21 @@
1718

1819

1920
class SetYamlOnOwnerInteractor(BaseInteractor):
20-
def validate(self):
21+
def validate(self) -> None:
2122
if not self.current_user.is_authenticated:
2223
raise Unauthenticated()
2324

24-
def authorize(self):
25+
def authorize(self) -> None:
2526
if not current_user_part_of_org(self.current_owner, self.owner):
2627
raise Unauthorized()
2728

28-
def get_owner(self, username):
29+
def get_owner(self, username: str) -> Owner:
2930
try:
3031
return Owner.objects.get(username=username, service=self.service)
3132
except Owner.DoesNotExist:
3233
raise NotFound()
3334

34-
def convert_yaml_to_dict(self, yaml_input):
35+
def convert_yaml_to_dict(self, yaml_input: str) -> Optional[dict]:
3536
yaml_safe = html.escape(yaml_input, quote=False)
3637
try:
3738
yaml_dict = yaml.safe_load(yaml_safe)
@@ -49,7 +50,7 @@ def convert_yaml_to_dict(self, yaml_input):
4950
raise ValidationError(message)
5051

5152
@sync_to_async
52-
def execute(self, username, yaml_input):
53+
def execute(self, username: str, yaml_input: str) -> Owner:
5354
self.validate()
5455
self.owner = self.get_owner(username)
5556
self.authorize()

graphql_api/types/owner/owner.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from hashlib import sha1
3-
from typing import Iterable, List, Optional
3+
from typing import Any, Iterable, List, Optional
44

55
import shared.rate_limits as rate_limits
66
import stripe
@@ -26,6 +26,7 @@
2626
)
2727
from graphql_api.helpers.ariadne import ariadne_load_local_graphql
2828
from graphql_api.helpers.connection import (
29+
Connection,
2930
build_connection_graphql,
3031
queryset_to_connection,
3132
)
@@ -38,7 +39,7 @@
3839
from services.profiling import ProfilingSummary
3940
from services.redis_configuration import get_redis_connection
4041
from timeseries.helpers import fill_sparse_measurements
41-
from timeseries.models import Interval, MeasurementSummary
42+
from timeseries.models import Interval
4243
from utils.config import get_config
4344

4445
owner = ariadne_load_local_graphql(__file__, "owner.graphql")
@@ -51,12 +52,12 @@
5152
@convert_kwargs_to_snake_case
5253
def resolve_repositories(
5354
owner: Owner,
54-
info,
55-
filters=None,
56-
ordering=RepositoryOrdering.ID,
57-
ordering_direction=OrderingDirection.ASC,
58-
**kwargs,
59-
):
55+
info: GraphQLResolveInfo,
56+
filters: Optional[dict] = None,
57+
ordering: Optional[RepositoryOrdering] = RepositoryOrdering.ID,
58+
ordering_direction: Optional[OrderingDirection] = OrderingDirection.ASC,
59+
**kwargs: Any,
60+
) -> Connection:
6061
current_owner = info.context["request"].current_owner
6162
okta_account_auths: list[int] = info.context["request"].session.get(
6263
OKTA_SIGNED_IN_ACCOUNTS_SESSION_KEY, []
@@ -81,18 +82,18 @@ def resolve_repositories(
8182

8283
@owner_bindable.field("isCurrentUserPartOfOrg")
8384
@sync_to_async
84-
def resolve_is_current_user_part_of_org(owner, info: GraphQLResolveInfo):
85+
def resolve_is_current_user_part_of_org(owner: Owner, info: GraphQLResolveInfo) -> bool:
8586
current_owner = info.context["request"].current_owner
8687
return current_user_part_of_org(current_owner, owner)
8788

8889

8990
@owner_bindable.field("yaml")
90-
def resolve_yaml(owner: Owner, info: GraphQLResolveInfo):
91+
def resolve_yaml(owner: Owner, info: GraphQLResolveInfo) -> Optional[str]:
9192
if owner.yaml is None:
92-
return
93+
return None
9394
current_owner = info.context["request"].current_owner
9495
if not current_user_part_of_org(current_owner, owner):
95-
return
96+
return None
9697
return owner.yaml.get("to_string", yaml.dump(owner.yaml))
9798

9899

@@ -134,7 +135,9 @@ def resolve_ownerid(owner: Owner, info: GraphQLResolveInfo) -> int:
134135

135136

136137
@owner_bindable.field("repository")
137-
async def resolve_repository(owner: Owner, info, name):
138+
async def resolve_repository(
139+
owner: Owner, info: GraphQLResolveInfo, name: str
140+
) -> Repository | NotFoundError:
138141
command = info.context["executor"].get_command("repository")
139142
okta_authenticated_accounts: list[int] = info.context["request"].session.get(
140143
OKTA_SIGNED_IN_ACCOUNTS_SESSION_KEY, []
@@ -174,37 +177,43 @@ async def resolve_repository(owner: Owner, info, name):
174177

175178
@owner_bindable.field("numberOfUploads")
176179
@require_part_of_org
177-
async def resolve_number_of_uploads(owner: Owner, info, **kwargs):
180+
async def resolve_number_of_uploads(
181+
owner: Owner, info: GraphQLResolveInfo, **kwargs: Any
182+
) -> int:
178183
command = info.context["executor"].get_command("owner")
179184
return await command.get_uploads_number_per_user(owner)
180185

181186

182187
@owner_bindable.field("isAdmin")
183188
@require_part_of_org
184-
def resolve_is_current_user_an_admin(owner: Owner, info: GraphQLResolveInfo):
189+
def resolve_is_current_user_an_admin(owner: Owner, info: GraphQLResolveInfo) -> bool:
185190
current_owner = info.context["request"].current_owner
186191
command = info.context["executor"].get_command("owner")
187192
return command.get_is_current_user_an_admin(owner, current_owner)
188193

189194

190195
@owner_bindable.field("hashOwnerid")
191196
@require_part_of_org
192-
def resolve_hash_ownerid(owner: Owner, info: GraphQLResolveInfo):
197+
def resolve_hash_ownerid(owner: Owner, info: GraphQLResolveInfo) -> str:
193198
hash_ownerid = sha1(str(owner.ownerid).encode())
194199
return hash_ownerid.hexdigest()
195200

196201

197202
@owner_bindable.field("orgUploadToken")
198203
@require_part_of_org
199-
def resolve_org_upload_token(owner: Owner, info, **kwargs):
204+
def resolve_org_upload_token(
205+
owner: Owner, info: GraphQLResolveInfo, **kwargs: Any
206+
) -> str:
200207
command = info.context["executor"].get_command("owner")
201208
return command.get_org_upload_token(owner)
202209

203210

204211
@owner_bindable.field("defaultOrgUsername")
205212
@sync_to_async
206213
@require_part_of_org
207-
def resolve_org_default_org_username(owner: Owner, info, **kwargs) -> int:
214+
def resolve_org_default_org_username(
215+
owner: Owner, info: GraphQLResolveInfo, **kwargs: Any
216+
) -> Optional[str]:
208217
return None if owner.default_org is None else owner.default_org.username
209218

210219

@@ -213,13 +222,13 @@ def resolve_org_default_org_username(owner: Owner, info, **kwargs) -> int:
213222
@convert_kwargs_to_snake_case
214223
def resolve_measurements(
215224
owner: Owner,
216-
info,
225+
info: GraphQLResolveInfo,
217226
interval: Interval,
218227
after: Optional[datetime] = None,
219228
before: Optional[datetime] = None,
220229
repos: Optional[List[str]] = None,
221230
is_public: Optional[bool] = None,
222-
) -> Iterable[MeasurementSummary]:
231+
) -> Iterable[dict]:
223232
current_owner = info.context["request"].current_owner
224233

225234
okta_authenticated_accounts: list[int] = info.context["request"].session.get(
@@ -256,7 +265,7 @@ def resolve_measurements(
256265

257266
@owner_bindable.field("isCurrentUserActivated")
258267
@sync_to_async
259-
def resolve_is_current_user_activated(owner: Owner, info: GraphQLResolveInfo):
268+
def resolve_is_current_user_activated(owner: Owner, info: GraphQLResolveInfo) -> bool:
260269
current_user = info.context["request"].user
261270
if not current_user.is_authenticated:
262271
return False
@@ -303,7 +312,7 @@ def resolve_is_github_rate_limited(
303312
@convert_kwargs_to_snake_case
304313
def resolve_owner_invoice(
305314
owner: Owner,
306-
info,
315+
info: GraphQLResolveInfo,
307316
invoice_id: str,
308317
) -> stripe.Invoice | None:
309318
return BillingService(requesting_user=owner).get_invoice(owner, invoice_id)
@@ -371,7 +380,9 @@ def resolve_ai_enabled_repos(
371380

372381
@owner_bindable.field("uploadTokenRequired")
373382
@require_part_of_org
374-
def resolve_upload_token_required(owner: Owner, info) -> bool | None:
383+
def resolve_upload_token_required(
384+
owner: Owner, info: GraphQLResolveInfo
385+
) -> bool | None:
375386
return owner.upload_token_required_for_public_repos
376387

377388

0 commit comments

Comments
 (0)