14
14
create_blame_query ,
15
15
extract_commits_from_blame_response ,
16
16
generate_file_path_mapping ,
17
+ is_graphql_response ,
17
18
)
18
19
from sentry .integrations .github .utils import get_jwt , get_next_link
19
20
from sentry .integrations .models .integration import Integration
30
31
from sentry .models .repository import Repository
31
32
from sentry .shared_integrations .client .proxy import IntegrationProxyClient
32
33
from sentry .shared_integrations .exceptions import ApiError , ApiRateLimitedError
33
- from sentry .shared_integrations .response .mapping import MappingApiResponse
34
34
from sentry .silo .base import control_silo_function
35
35
from sentry .utils import metrics
36
36
@@ -210,7 +210,7 @@ def get_access_token(self) -> AccessTokenData | None:
210
210
access_token : str | None = self .integration .metadata .get ("access_token" )
211
211
expires_at : str | None = self .integration .metadata .get ("expires_at" )
212
212
is_expired = (
213
- bool ( expires_at ) and datetime .fromisoformat (expires_at ).replace (tzinfo = None ) < now
213
+ expires_at is not None and datetime .fromisoformat (expires_at ).replace (tzinfo = None ) < now
214
214
)
215
215
should_refresh = not access_token or not expires_at or is_expired
216
216
@@ -230,7 +230,7 @@ def authorize_request(self, prepared_request: PreparedRequest) -> PreparedReques
230
230
integration : RpcIntegration | Integration | None = None
231
231
if hasattr (self , "integration" ):
232
232
integration = self .integration
233
- elif hasattr ( self , " org_integration_id" ) :
233
+ elif self . org_integration_id is not None :
234
234
integration = Integration .objects .filter (
235
235
organizationintegration__id = self .org_integration_id ,
236
236
provider = EXTERNAL_PROVIDERS [ExternalProviders .GITHUB ],
@@ -430,7 +430,7 @@ def get_repos(self) -> list[dict[str, Any]]:
430
430
It uses page_size from the base class to specify how many items per page.
431
431
The upper bound of requests is controlled with self.page_number_limit to prevent infinite requests.
432
432
"""
433
- return self .get_with_pagination ("/installation/repositories" , response_key = "repositories" )
433
+ return self ._get_with_pagination ("/installation/repositories" , response_key = "repositories" )
434
434
435
435
def search_repositories (self , query : bytes ) -> Mapping [str , Sequence [Any ]]:
436
436
"""
@@ -445,9 +445,9 @@ def get_assignees(self, repo: str) -> Sequence[Any]:
445
445
"""
446
446
https://docs.github.com/en/rest/issues/assignees#list-assignees
447
447
"""
448
- return self .get_with_pagination (f"/repos/{ repo } /assignees" )
448
+ return self ._get_with_pagination (f"/repos/{ repo } /assignees" )
449
449
450
- def get_with_pagination (
450
+ def _get_with_pagination (
451
451
self , path : str , response_key : str | None = None , page_number_limit : int | None = None
452
452
) -> list [Any ]:
453
453
"""
@@ -549,7 +549,7 @@ def get_labels(self, owner: str, repo: str) -> list[Any]:
549
549
Fetches all labels for a repository.
550
550
https://docs.github.com/en/rest/issues/labels#list-labels-for-a-repository
551
551
"""
552
- return self .get_with_pagination (f"/repos/{ owner } /{ repo } /labels" )
552
+ return self ._get_with_pagination (f"/repos/{ owner } /{ repo } /labels" )
553
553
554
554
def check_file (self , repo : Repository , path : str , version : str | None ) -> object | None :
555
555
return self .head_cached (path = f"/repos/{ repo .name } /contents/{ path } " , params = {"ref" : version })
@@ -580,7 +580,7 @@ def get_file(
580
580
581
581
def get_blame_for_files (
582
582
self , files : Sequence [SourceLineInfo ], extra : dict [str , Any ]
583
- ) -> Sequence [FileBlameInfo ]:
583
+ ) -> list [FileBlameInfo ]:
584
584
log_info = {
585
585
** extra ,
586
586
"provider" : IntegrationProviderSlug .GITHUB ,
@@ -633,7 +633,7 @@ def get_blame_for_files(
633
633
else :
634
634
self .set_cache (cache_key , response , 60 )
635
635
636
- if not isinstance (response , MappingApiResponse ):
636
+ if not is_graphql_response (response ):
637
637
raise ApiError ("Response is not JSON" )
638
638
639
639
errors = response .get ("errors" , [])
@@ -662,6 +662,10 @@ def get_blame_for_files(
662
662
)
663
663
664
664
665
+ class _IntegrationIdParams (TypedDict , total = False ):
666
+ integration_id : int
667
+
668
+
665
669
class GitHubApiClient (GitHubBaseClient ):
666
670
def __init__ (
667
671
self ,
@@ -671,7 +675,7 @@ def __init__(
671
675
logging_context : Mapping [str , Any ] | None = None ,
672
676
) -> None :
673
677
self .integration = integration
674
- kwargs = {}
678
+ kwargs : _IntegrationIdParams = {}
675
679
if hasattr (self .integration , "id" ):
676
680
kwargs ["integration_id" ] = integration .id
677
681
0 commit comments