33import click
44import github
55from github .ContentFile import ContentFile
6+ from github .GithubException import GithubException
67from github .Rate import Rate
78from github .RateLimit import RateLimit
89
@@ -52,13 +53,25 @@ def __init__(self, client: github.Github, filters: List[Filter], verbose: bool =
5253 self .filters = filters
5354 self .verbose = verbose
5455
56+ def get_rate_limit (self ) -> RateLimit | None :
57+ try :
58+ return self .client .get_rate_limit ()
59+ except GithubException as ge :
60+ # 404 means that rate limiting is disabled
61+ if ge .status == 404 :
62+ return None
63+ raise ge
64+
5565 def get_filtered_results (self , query : List [str ]) -> List [ContentFile ]:
56- rate_limit = self .client .get_rate_limit ()
57- if self .verbose :
66+ rate_limit = self .get_rate_limit ()
67+
68+ if rate_limit and self .verbose :
5869 _echo_rate_limits (rate_limit )
5970
6071 results = self .client .search_code (query = " " .join (query ))
61- self ._check_core_limit_threshold (results .totalCount , rate_limit .core )
72+
73+ if rate_limit :
74+ self ._check_core_limit_threshold (results .totalCount , rate_limit .core )
6275
6376 filtered_results = []
6477 with ProgressPrinter (overwrite = not self .verbose ) as printer :
@@ -74,8 +87,9 @@ def get_filtered_results(self, query: List[str]) -> List[ContentFile]:
7487 elif self .verbose :
7588 click .echo (f"Skipping result for { result .repository .full_name } via { exclude_reason } " )
7689
77- if self .verbose :
78- _echo_rate_limits (self .client .get_rate_limit ())
90+ rate_limit = self .get_rate_limit ()
91+ if rate_limit and self .verbose :
92+ _echo_rate_limits (rate_limit )
7993
8094 return filtered_results
8195
0 commit comments