@@ -40,7 +40,6 @@ DEFAULT_IN = ROOT.joinpath("vim-plugin-names")
4040DEFAULT_OUT = ROOT.joinpath("generated.nix")
4141DEPRECATED = ROOT.joinpath("deprecated.json")
4242
43−
4443def retry(ExceptionToCheck: Any, tries: int = 4, delay: float = 3, backoff: float = 2):
4544 """Retry calling the decorated function using an exponential backoff.
4645 http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
@@ -71,6 +70,12 @@ def retry(ExceptionToCheck: Any, tries: int = 4, delay: float = 3, backoff: floa
7170
7271 return deco_retry
7372
73+def make_request(url: str) -> urllib.request.Request:
74+ token = os.getenv("GITHUB_API_TOKEN")
75+ headers = {}
76+ if token is not None:
77+ headers["Authorization"] = f"token {token}"
78+ return urllib.request.Request(url, headers=headers)
7479
7580class Repo:
7681 def __init__(
@@ -91,9 +96,8 @@ class Repo:
9196 @retry(urllib.error.URLError, tries=4, delay=3, backoff=2)
9297 def has_submodules(self) -> bool:
9398 try:
94− urllib.request.urlopen(
95− self.url(f"blob/{self.branch}/.gitmodules"), timeout=10
96− ).close()
99+ req = make_request(self.url(f"blob/{self.branch}/.gitmodules"))
100+ urllib.request.urlopen(req, timeout=10).close()
97101 except urllib.error.HTTPError as e:
98102 if e.code == 404:
99103 return False
@@ -104,7 +108,8 @@ class Repo:
104108 @retry(urllib.error.URLError, tries=4, delay=3, backoff=2)
105109 def latest_commit(self) -> Tuple[str, datetime]:
106110 commit_url = self.url(f"commits/{self.branch}.atom")
107− with urllib.request.urlopen(commit_url, timeout=10) as req:
111+ commit_req = make_request(commit_url)
112+ with urllib.request.urlopen(commit_req, timeout=10) as req:
108113 self.check_for_redirect(commit_url, req)
109114 xml = req.read()
110115 root = ET.fromstring(xml)