66import httpx
77from jsonpointer import JsonPointer
88
9+ GITHUB_TOKEN = os .getenv ("GITHUB_TOKEN" )
910REPO_COMMIT = os .getenv (
1011 "REPO_COMMIT" ,
1112 "https://api.github.com/repos/github/rest-api-description/commits/main" ,
@@ -52,6 +53,13 @@ def __truediv__(self, other: str | int) -> "Source":
5253 return self .resolve_ref (str (httpx .URL (fragment = fragment )))
5354
5455
56+ @cache
57+ def _get_auth_header () -> dict [str , str ]:
58+ if GITHUB_TOKEN :
59+ return {"Authorization" : f"Bearer { GITHUB_TOKEN } " }
60+ return {}
61+
62+
5563@cache
5664def get_content (source : str | httpx .URL ) -> tuple [httpx .URL , dict ]:
5765 if isinstance (source , str ):
@@ -60,6 +68,7 @@ def get_content(source: str | httpx.URL) -> tuple[httpx.URL, dict]:
6068 headers = {
6169 "User-Agent" : "GitHubKit Codegen" ,
6270 "Accept" : "application/vnd.github.sha" ,
71+ ** _get_auth_header (),
6372 },
6473 timeout = httpx .Timeout (10.0 ),
6574 )
@@ -70,7 +79,9 @@ def get_content(source: str | httpx.URL) -> tuple[httpx.URL, dict]:
7079 source_link = source
7180
7281 response = httpx .get (
73- source_link , headers = {"User-Agent" : "GitHubKit Codegen" }, follow_redirects = True
82+ source_link ,
83+ headers = {"User-Agent" : "GitHubKit Codegen" , ** _get_auth_header ()},
84+ follow_redirects = True ,
7485 )
7586 response .raise_for_status ()
7687 uri = response .url
0 commit comments