4242import requests
4343import yaml
4444
45+ api_token = os .environ .get ("GITHUB_TOKEN" )
46+ if api_token is not None :
47+ GITHUB_API_HEADERS = {"Authorization" : f"Bearer { api_token } " }
48+ else :
49+ GITHUB_API_HEADERS = {}
50+
4551
4652class Preprocessors :
4753 """
@@ -166,7 +172,9 @@ def maintainers_add_info(context):
166172 for kind in ("active" , "inactive" ):
167173 context ["maintainers" ][f"{ kind } _with_github_info" ] = []
168174 for user in context ["maintainers" ][kind ]:
169- resp = requests .get (f"https://api.github.com/users/{ user } " )
175+ resp = requests .get (
176+ f"https://api.github.com/users/{ user } " , headers = GITHUB_API_HEADERS
177+ )
170178 if context ["ignore_io_errors" ] and resp .status_code == 403 :
171179 return context
172180 resp .raise_for_status ()
@@ -178,7 +186,10 @@ def home_add_releases(context):
178186 context ["releases" ] = []
179187
180188 github_repo_url = context ["main" ]["github_repo_url" ]
181- resp = requests .get (f"https://api.github.com/repos/{ github_repo_url } /releases" )
189+ resp = requests .get (
190+ f"https://api.github.com/repos/{ github_repo_url } /releases" ,
191+ headers = GITHUB_API_HEADERS ,
192+ )
182193 if context ["ignore_io_errors" ] and resp .status_code == 403 :
183194 return context
184195 resp .raise_for_status ()
@@ -245,7 +256,8 @@ def roadmap_pdeps(context):
245256 github_repo_url = context ["main" ]["github_repo_url" ]
246257 resp = requests .get (
247258 "https://api.github.com/search/issues?"
248- f"q=is:pr is:open label:PDEP repo:{ github_repo_url } "
259+ f"q=is:pr is:open label:PDEP repo:{ github_repo_url } " ,
260+ headers = GITHUB_API_HEADERS ,
249261 )
250262 if context ["ignore_io_errors" ] and resp .status_code == 403 :
251263 return context
0 commit comments