Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass OAuth token through header #340

Merged
merged 1 commit into from Nov 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions docs/source/ext/github_tools.py
Expand Up @@ -19,7 +19,7 @@
from datetime import datetime, timedelta
from subprocess import check_output

from urllib.request import urlopen
from urllib.request import urlopen, Request

# ----------------------------------------------------------------------------
# Globals
Expand All @@ -34,7 +34,6 @@
LAST_RELEASE = datetime(2015, 3, 18)
CONTRIBUTORS_FILE = "contributors.json"
GH_TOKEN = os.environ.get('GH_TOKEN', '')
TOKEN_URL = "access_token={}".format(GH_TOKEN) if GH_TOKEN else ''


# ----------------------------------------------------------------------------
Expand All @@ -43,17 +42,15 @@


def fetch_url(url):
if TOKEN_URL:
if "?" in url:
url += "&{0}".format(TOKEN_URL)
else:
url += "?{0}".format(TOKEN_URL)
req = Request(url)
if GH_TOKEN:
req.add_header('Authorization', 'token {0}'.format(GH_TOKEN))
try:
print("fetching %s" % url, file=sys.stderr)
# url = Request(url,
# headers={'Accept': 'application/vnd.github.v3+json',
# 'User-agent': 'Defined'})
f = urlopen(url)
f = urlopen(req)
except Exception as e:
print(e)
print("return Empty data", file=sys.stderr)
Expand Down