File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 66import pathlib
77import re
88import sys
9+ from time import time
910from typing import Any , Optional , Tuple
1011
1112import certifi
@@ -74,6 +75,7 @@ def authorization(self) -> Optional[Tuple[str, str]]:
7475
7576class GitHub (Provider ):
7677 def __init__ (self , repo , cache_dir : str ) -> None :
78+ self ._rate_limit : Optional [int ] = None
7779 file_path = os .path .join (cache_dir , 'github.json' )
7880 super ().__init__ (repo , Cache (file_path ))
7981
@@ -111,9 +113,13 @@ def provide(self, subject: str) -> str:
111113 try :
112114 return self ._cache [subject ]
113115 except KeyError :
114- if self .auth_failed :
116+ if (self ._rate_limit and self ._rate_limit >= time ()) \
117+ or self .auth_failed :
115118 return subject
116119
120+ if self ._rate_limit :
121+ self ._rate_limit = None
122+
117123 results = self .pattern .search (subject )
118124 if results :
119125 _id = results .group (1 )
@@ -130,6 +136,10 @@ def provide(self, subject: str) -> str:
130136 print ('Failed to authenticate' , file = sys .stderr )
131137 self .auth_failed = True
132138 return subject
139+ elif request .status == 403 :
140+ self ._rate_limit = int (
141+ request .headers ['X-Ratelimit-Reset' ])
142+ return subject
133143 else :
134144 print (request .data , file = sys .stderr )
135145 return subject
You can’t perform that action at this time.
0 commit comments