Skip to content

Commit d7766e5

Browse files
Add GitHub authentication for PyGithub with env var GITHUB_TOKEN
1 parent 1f14cff commit d7766e5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

container/libs/github.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
from datetime import datetime, MINYEAR
1+
import os
2+
from datetime import datetime, MINYEAR
23
from github import Github, GitRelease, Repository, GithubException
34

45
def get_latest_github_repo_version(repo):
5-
client = Github()
6+
# check for a github token that may be used alongside the codeql cli to upload github results
7+
# this will limit rate limting 403 errors on checking codeql versions, as the request will be authenticated if possible.
8+
# by default codeql uses env var "GITHUB_TOKEN" to authenticate
9+
# https://codeql.github.com/docs/codeql-cli/manual/github-upload-results/
10+
access_token = os.getenv('GITHUB_TOKEN')
11+
client = Github(access_token) if access_token != None else Github()
612
repo = client.get_repo(repo)
713
releases = repo.get_releases()
814
latest_release = get_latest_github_release(releases)

0 commit comments

Comments
 (0)