4
4
from datetime import date
5
5
from enum import Enum
6
6
from math import log
7
+ from os import getenv
7
8
from pathlib import Path
8
9
from pprint import pp
9
10
from sys import exit
@@ -58,8 +59,6 @@ def eprint(*args, **kwargs):
58
59
'mixed' : [],
59
60
}
60
61
61
- pr_titles = dict ()
62
-
63
62
64
63
def get_username ():
65
64
usernames = {'mackendy' : 'ecstaticmorse' , 'joshua' : 'jyn514' }
@@ -175,14 +174,23 @@ def gh_link(pr):
175
174
176
175
177
176
def 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' , '' )
180
186
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
186
194
187
195
188
196
def compare_link (start , end , stat ):
@@ -195,7 +203,7 @@ def write_section(res, *changes):
195
203
end = res ['b' ]['commit' ]
196
204
title = gh_pr_title (pr )
197
205
198
- msg = f'{ title } [#{ pr } ]({ gh_link (pr )} )'
206
+ msg = f'{ title } [#{ pr } ]({ gh_link (pr )} )'
199
207
200
208
for change in changes :
201
209
msg += '\n - '
0 commit comments