Skip to content

Commit

Permalink
Merge pull request dusty-nv#341 from tokk-nv/dev-github-token-env
Browse files Browse the repository at this point in the history
[jp6] Use the GITHUB_TOKEN env varialble for GitHub API call
  • Loading branch information
dusty-nv authored Dec 7, 2023
2 parents 7770224 + baed868 commit 67e1bc8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jetson_containers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import pprint
import urllib.request
from urllib.request import urlopen, Request


def check_dependencies(install=True):
Expand Down Expand Up @@ -127,7 +128,14 @@ def github_latest_commit(repo, branch='main'):
Returns the SHA of the latest commit to the given github user/repo/branch.
"""
url = f"https://api.github.com/repos/{repo}/commits/{branch}"
response = urllib.request.urlopen(url)
github_token = os.environ.get('GITHUB_TOKEN')
print(f"[ENV] GITHUB_TOKEN: {github_token}")
if github_token:
headers = {'Authorization': 'token %s' % github_token}
request = Request(url, headers=headers)
else:
request = Request(url)
response = urlopen(request)
data = response.read()
encoding = response.info().get_content_charset('utf-8')
msg = json.loads(data.decode(encoding))
Expand Down

0 comments on commit 67e1bc8

Please sign in to comment.