Skip to content

Commit 14d7b87

Browse files
authored
Merge pull request #47 from travisgosselin/feature/github-token-support
Support Authenticated GitHub Requests in Setup
2 parents dde21e8 + 37f7d04 commit 14d7b87

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
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)

container/setup.py

100755100644
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ def setup():
3838
# check version and download the latest version
3939
get_latest_codeql(args)
4040
logger.info("End setup...")
41+
4142
def get_latest_codeql(args):
4243
codeql = CodeQL(CODEQL_HOME)
43-
# what version do we have?
44+
current_installed_version = codeql.get_current_local_version()
45+
logger.info(f'Current codeql version: {current_installed_version}')
46+
# ensure we only query for the latest codeql cli version if we might actually update it
4447
if args.check_latest_cli:
45-
current_installed_version = codeql.get_current_local_version()
46-
logger.info(f'Current codeql version: {current_installed_version}')
4748
latest_online_version = codeql.get_latest_codeql_github_version()
4849
if current_installed_version != latest_online_version.title:
4950
# we got a newer version online, download and install it

0 commit comments

Comments
 (0)