@@ -94,6 +94,13 @@ class GitHubReaction(StrEnum):
9494 EYES = "eyes"
9595
9696
97+ class GitHubApiEndpoint (StrEnum ):
98+ COMPARE_COMMITS = "compare_commits"
99+ GET_COMMITS = "get_commits"
100+ GET_COMMIT = "get_commit"
101+ CHECK_FILE = "check_file"
102+
103+
97104class GithubSetupApiClient (IntegrationProxyClient ):
98105 """
99106 API Client that doesn't require an installation.
@@ -342,7 +349,11 @@ def get_last_commits(self, repo: str, end_sha: str) -> Sequence[Any]:
342349 see https://docs.github.com/en/rest/commits/commits#list-commits-on-a-repository
343350 using end_sha as parameter.
344351 """
345- return self .get_cached (f"/repos/{ repo } /commits" , params = {"sha" : end_sha })
352+ return self .get_cached (
353+ f"/repos/{ repo } /commits" ,
354+ params = {"sha" : end_sha },
355+ endpoint = GitHubApiEndpoint .GET_COMMITS ,
356+ )
346357
347358 def compare_commits (self , repo : str , start_sha : str , end_sha : str ) -> list [Any ]:
348359 """
@@ -352,6 +363,7 @@ def compare_commits(self, repo: str, start_sha: str, end_sha: str) -> list[Any]:
352363 return self ._get_with_pagination (
353364 f"/repos/{ repo } /compare/{ start_sha } ...{ end_sha } " ,
354365 response_key = "commits" ,
366+ endpoint = GitHubApiEndpoint .COMPARE_COMMITS ,
355367 )
356368
357369 def repo_hooks (self , repo : str ) -> Sequence [Any ]:
@@ -364,13 +376,15 @@ def get_commits(self, repo: str) -> Sequence[Any]:
364376 """
365377 https://docs.github.com/en/rest/commits/commits#list-commits
366378 """
367- return self .get (f"/repos/{ repo } /commits" )
379+ return self .get (f"/repos/{ repo } /commits" , endpoint = GitHubApiEndpoint . GET_COMMITS )
368380
369381 def get_commit (self , repo : str , sha : str ) -> Any :
370382 """
371383 https://docs.github.com/en/rest/commits/commits#get-a-commit
372384 """
373- return self .get_cached (f"/repos/{ repo } /commits/{ sha } " )
385+ return self .get_cached (
386+ f"/repos/{ repo } /commits/{ sha } " , endpoint = GitHubApiEndpoint .GET_COMMIT
387+ )
374388
375389 def get_installation_info (self , installation_id : int | str ) -> Any :
376390 """
@@ -601,7 +615,11 @@ def get_assignees(self, repo: str) -> Sequence[Any]:
601615 return self ._get_with_pagination (f"/repos/{ repo } /assignees" )
602616
603617 def _get_with_pagination (
604- self , path : str , response_key : str | None = None , page_number_limit : int | None = None
618+ self ,
619+ path : str ,
620+ response_key : str | None = None ,
621+ page_number_limit : int | None = None ,
622+ endpoint : GitHubApiEndpoint | None = None ,
605623 ) -> list [Any ]:
606624 """
607625 Github uses the Link header to provide pagination links. Github
@@ -622,7 +640,7 @@ def _get_with_pagination(
622640 output : list [dict [str , Any ]] = []
623641
624642 page_number = 1
625- resp = self .get (path , params = {"per_page" : self .page_size })
643+ resp = self .get (path , params = {"per_page" : self .page_size }, endpoint = endpoint )
626644 output .extend (resp ) if not response_key else output .extend (resp [response_key ])
627645 next_link = get_next_link (resp )
628646
@@ -631,7 +649,7 @@ def _get_with_pagination(
631649 while next_link and page_number < page_number_limit :
632650 # If a per_page is specified, GitHub preserves the per_page value
633651 # in the response headers.
634- resp = self .get (next_link )
652+ resp = self .get (next_link , endpoint = endpoint )
635653 output .extend (resp ) if not response_key else output .extend (resp [response_key ])
636654
637655 next_link = get_next_link (resp )
@@ -761,7 +779,11 @@ def get_labels(self, owner: str, repo: str) -> list[Any]:
761779 return self ._get_with_pagination (f"/repos/{ owner } /{ repo } /labels" )
762780
763781 def check_file (self , repo : Repository , path : str , version : str | None ) -> object | None :
764- return self .head_cached (path = f"/repos/{ repo .name } /contents/{ path } " , params = {"ref" : version })
782+ return self .head_cached (
783+ path = f"/repos/{ repo .name } /contents/{ path } " ,
784+ params = {"ref" : version },
785+ endpoint = GitHubApiEndpoint .CHECK_FILE ,
786+ )
765787
766788 def get_file (
767789 self , repo : Repository , path : str , ref : str | None , codeowners : bool = False
0 commit comments