From d7766e5c2e2fb94dff21aa4fc307ef91ab7e90e2 Mon Sep 17 00:00:00 2001 From: travisgosselin Date: Wed, 7 Dec 2022 15:28:05 -0500 Subject: [PATCH] Add GitHub authentication for PyGithub with env var GITHUB_TOKEN --- container/libs/github.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/container/libs/github.py b/container/libs/github.py index 32547f9..d576216 100644 --- a/container/libs/github.py +++ b/container/libs/github.py @@ -1,8 +1,14 @@ -from datetime import datetime, MINYEAR +import os +from datetime import datetime, MINYEAR from github import Github, GitRelease, Repository, GithubException def get_latest_github_repo_version(repo): - client = Github() + # check for a github token that may be used alongside the codeql cli to upload github results + # this will limit rate limting 403 errors on checking codeql versions, as the request will be authenticated if possible. + # by default codeql uses env var "GITHUB_TOKEN" to authenticate + # https://codeql.github.com/docs/codeql-cli/manual/github-upload-results/ + access_token = os.getenv('GITHUB_TOKEN') + client = Github(access_token) if access_token != None else Github() repo = client.get_repo(repo) releases = repo.get_releases() latest_release = get_latest_github_release(releases)