Skip to content

Commit eab245a

Browse files
committed
Merge branch 'master' of github.com:tobami/codespeed into fix_authentication_bug
2 parents bed3f63 + b362022 commit eab245a

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

codespeed/commits/github.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
try:
1212
# Python 3
1313
from urllib.request import urlopen
14+
from urllib.request import Request
1415
except ImportError:
1516
# Python 2
16-
from urllib import urlopen
17+
from urllib2 import urlopen
18+
from urllib2 import Request
1719
import re
1820
import json
1921

2022
import isodate
23+
from django.conf import settings
2124
from django.core.cache import cache
2225

2326
from .exceptions import CommitLogError
@@ -42,8 +45,17 @@ def fetch_json(url):
4245
json_obj = cache.get(url)
4346

4447
if json_obj is None:
48+
github_oauth_token = getattr(settings, 'GITHUB_OAUTH_TOKEN', None)
49+
50+
if github_oauth_token:
51+
headers = {'Authorization': 'token %s' % (github_oauth_token)}
52+
else:
53+
headers = {}
54+
55+
request = Request(url=url, headers=headers)
56+
4557
try:
46-
json_obj = json.load(urlopen(url))
58+
json_obj = json.load(urlopen(request))
4759
except IOError as e:
4860
logger.exception("Unable to load %s: %s",
4961
url, e, exc_info=True)

codespeed/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@
8383

8484
ALLOW_ANONYMOUS_POST = True # Whether anonymous users can post results
8585
REQUIRE_SECURE_AUTH = True # Whether auth needs to be over a secure channel
86+
87+
GITHUB_OAUTH_TOKEN = None # Github oAuth token to use when using Github repo type. If not
88+
# specified, it will utilize unauthenticated requests which have
89+
# low rate limits.

codespeed/templates/codespeed/timeline.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% block extra_head %}
88
{{ block.super }}
9-
<link rel="stylesheet" type="text/css" href="{% static '/css/timeline.css' %}" />
9+
<link rel="stylesheet" type="text/css" href="{% static 'css/timeline.css' %}" />
1010
<link rel="stylesheet" type="text/css" href="{% static 'js/jqplot/jquery.jqplot.min.css' %}" />
1111
{% endblock %}
1212

0 commit comments

Comments
 (0)