From 234e323743a48c3818313c887d029233fd210a15 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 31 Dec 2022 15:05:48 -0500 Subject: Use authenticated API call for github API for better rate limits --- build-scripts/download-external-libs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'build-scripts/download-external-libs') diff --git a/build-scripts/download-external-libs b/build-scripts/download-external-libs index 5c437c23..79c9d348 100755 --- a/build-scripts/download-external-libs +++ b/build-scripts/download-external-libs @@ -30,16 +30,23 @@ src_name = 'qpdf-external-libs-src.zip' dir_name = 'external-libs-dist' os.makedirs(dir_name, exist_ok=True) -r = requests.get( - 'https://api.github.com/repos/qpdf/external-libs/releases') -releases = json.loads(r.text) +github_headers = { + 'content-type': 'application/json', +} +try: + token = sys.argv[1] + github_headers['authorization'] = f'Bearer {token}' +except IndexError: + print('WARNING: unauthenticated call to github API' + ' will be subject to more stringent rate limits.') -# Help diagnose occasional failure where some releases don't have -# 'prerelease'. I've never seen this in attempts to reproduce. -print("---- github API output for external-libs releaes ----") -print(json.dumps(releases, indent=2, separators=(',', ': '))) -print("--------") +r = requests.get( + 'https://api.github.com/repos/qpdf/external-libs/releases', + headers=github_headers) +if r.status_code >= 400: + exit(f'GitHub API call returned status {r.status_code}: {r.text}') +releases = json.loads(r.text) by_tag = sorted( [(r['tag_name'], r) for r in releases if r['prerelease'] is False], -- cgit v1.2.3-54-g00ecf