22
33import json
44import logging
5- import time
65import re
6+ import time
77from typing import Any , Dict , Optional , Sequence , Tuple , Union
8- from datetime import datetime
98
109import requests
1110
1413MAX_RETRIES = 5
1514INITIAL_BACKOFF_SECONDS = 60
1615
16+
1717class RealGitHubEndpoint (ghstack .github .GitHubEndpoint ):
1818 """
1919 A class representing a GitHub endpoint we can send queries to.
@@ -192,33 +192,39 @@ def rest(self, method: str, path: str, **kwargs: Any) -> Any:
192192
193193 if remaining_count == "0" and reset_time :
194194 sleep_time = int (reset_time ) - int (time .time ())
195- logging .warning (f"Rate limit exceeded. Sleeping until reset in { sleep_time } seconds." )
195+ logging .warning (
196+ f"Rate limit exceeded. Sleeping until reset in { sleep_time } seconds."
197+ )
196198 time .sleep (sleep_time )
197199 continue
198200 else :
199201 retry_after_seconds = resp .headers .get ("retry-after" )
200202 if retry_after_seconds :
201203 sleep_time = int (retry_after_seconds )
202- logging .warning (f"Secondary rate limit hit. Sleeping for { sleep_time } seconds." )
204+ logging .warning (
205+ f"Secondary rate limit hit. Sleeping for { sleep_time } seconds."
206+ )
203207 else :
204208 sleep_time = backoff_seconds
205- logging .warning (f"Secondary rate limit hit. Sleeping for { sleep_time } seconds (exponential backoff)." )
209+ logging .warning (
210+ f"Secondary rate limit hit. Sleeping for { sleep_time } seconds (exponential backoff)."
211+ )
206212 backoff_seconds *= 2
207213 time .sleep (sleep_time )
208- continue
214+ continue
209215
210216 if resp .status_code == 404 :
211217 raise ghstack .github .NotFoundError (
212218 """\
213- GitHub raised a 404 error on the request for
214- {url}.
215- Usually, this doesn't actually mean the page doesn't exist; instead, it
216- usually means that you didn't configure your OAuth token with enough
217- permissions. Please create a new OAuth token at
218- https://{github_url}/settings/tokens and DOUBLE CHECK that you checked
219- "public_repo" for permissions, and update ~/.ghstackrc with your new
220- value.
221- """ .format (
219+ GitHub raised a 404 error on the request for
220+ {url}.
221+ Usually, this doesn't actually mean the page doesn't exist; instead, it
222+ usually means that you didn't configure your OAuth token with enough
223+ permissions. Please create a new OAuth token at
224+ https://{github_url}/settings/tokens and DOUBLE CHECK that you checked
225+ "public_repo" for permissions, and update ~/.ghstackrc with your new
226+ value.
227+ """ .format (
222228 url = url , github_url = self .github_url
223229 )
224230 )
@@ -229,5 +235,5 @@ def rest(self, method: str, path: str, **kwargs: Any) -> Any:
229235 raise RuntimeError (pretty_json )
230236
231237 return r
232-
233- raise RuntimeError (f "Exceeded maximum retries due to GitHub rate limiting" )
238+
239+ raise RuntimeError ("Exceeded maximum retries due to GitHub rate limiting" )
0 commit comments