44from datetime import date
55from enum import Enum
66from math import log
7+ from os import getenv
78from pathlib import Path
89from pprint import pp
910from sys import exit
@@ -58,8 +59,6 @@ def eprint(*args, **kwargs):
5859 'mixed' : [],
5960}
6061
61- pr_titles = dict ()
62-
6362
6463def get_username ():
6564 usernames = {'mackendy' : 'ecstaticmorse' , 'joshua' : 'jyn514' }
@@ -175,14 +174,23 @@ def gh_link(pr):
175174
176175
177176def gh_pr_title (pr ):
178- if pr in pr_titles :
179- return pr_titles .get (pr )
177+ def make_req ():
178+ url = f'https://api.github.com/repos/rust-lang/rust/pulls/{ pr } '
179+ req = urllib .request .Request (url )
180+ req .add_header ('Content-Type' , 'application/json' )
181+ req .add_header ('Authorization' , f'token { getenv ("GITHUB_TOKEN" )} ' )
182+
183+ with urllib .request .urlopen (req ) as f :
184+ data = json .loads (f .read ())
185+ return data .get ('title' , '' )
180186
181- url = f'https://api.github.com/repos/rust-lang/rust/pulls/{ pr } '
182- with urllib .request .urlopen (url ) as f :
183- data = json .loads (f .read ())
184- pr_titles [pr ] = data ['title' ]
185- return pr_titles [pr ]
187+ result = ''
188+ try :
189+ result = make_req ()
190+ except urllib .error .HTTPError as e :
191+ eprint (e )
192+ finally :
193+ return result
186194
187195
188196def compare_link (start , end , stat ):
@@ -195,7 +203,7 @@ def write_section(res, *changes):
195203 end = res ['b' ]['commit' ]
196204 title = gh_pr_title (pr )
197205
198- msg = f'{ title } [#{ pr } ]({ gh_link (pr )} )'
206+ msg = f'{ title } [#{ pr } ]({ gh_link (pr )} )'
199207
200208 for change in changes :
201209 msg += '\n - '
0 commit comments