Skip to content

Commit 6aacee9

Browse files
author
Phil Opaola
committed
Update github.py to relfect newest version of github's API. Change changes_log/changes_table templates to use commit_id instead of commit_id
1 parent cc593d0 commit 6aacee9

3 files changed

Lines changed: 25 additions & 24 deletions

File tree

codespeed/github.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
logger = logging.getLogger(__name__)
2020

2121
GITHUB_URL_RE = re.compile(
22-
r'^(?P<proto>\w+)://github.com/(?P<username>[^/]+)/(?P<project>[^/]+)[.]git$')
22+
r'^(?P<proto>\w+)://github.com/(?P<username>[^/]+)/(?P<project>[^/]+)([.]git)?$')
2323

2424
# We currently use a simple linear search of on a single parent to retrieve
2525
# the history. This is often good enough, but might miss the actual starting
@@ -33,7 +33,7 @@ def updaterepo(project, update=True):
3333

3434

3535
def retrieve_revision(commit_id, username, project, revision=None):
36-
commit_url = 'http://github.com/api/v2/json/commits/show/%s/%s/%s' % (
36+
commit_url = 'https://api.github.com/repos/%s/%s/git/commits/%s' % (
3737
username, project, commit_id)
3838

3939
commit_json = cache.get(commit_url)
@@ -46,20 +46,18 @@ def retrieve_revision(commit_id, username, project, revision=None):
4646
commit_url, e, exc_info=True)
4747
raise e
4848

49-
if 'error' in commit_json:
49+
if commit_json["message"] in ("Not Found", "Server Error",):
5050
# We'll still cache these for a brief period of time to avoid making too many requests:
5151
cache.set(commit_url, commit_json, 300)
5252
else:
5353
# We'll cache successes for a very long period of time since
5454
# SCM diffs shouldn't change:
5555
cache.set(commit_url, commit_json, 86400 * 30)
5656

57-
if 'error' in commit_json:
58-
raise RuntimeError("Unable to load %s: %s" % (commit_url, commit_json['error']))
57+
if commit_json["message"] in ("Not Found", "Server Error",):
58+
raise RuntimeError("Unable to load %s: %s" % (commit_url, commit_json["message"]))
5959

60-
commit = commit_json['commit']
61-
62-
date = isodate.parse_datetime(commit['committed_date'])
60+
date = isodate.parse_datetime(commit_json['committer']['date'])
6361

6462
if revision:
6563
# Overwrite any existing data we might have for this revision since
@@ -68,19 +66,19 @@ def retrieve_revision(commit_id, username, project, revision=None):
6866
# We need to convert the timezone-aware date to a naive (i.e.
6967
# timezone-less) date in UTC to avoid killing MySQL:
7068
revision.date = date.astimezone(isodate.tzinfo.Utc()).replace(tzinfo=None)
71-
revision.author = commit['author']['name']
72-
revision.message = commit['message']
69+
revision.author = commit_json['author']['name']
70+
revision.message = commit_json['message']
7371
revision.full_clean()
7472
revision.save()
7573

7674
return {'date': date,
77-
'message': commit['message'],
75+
'message': commit_json['message'],
7876
'body': "", # TODO: pretty-print diffs
79-
'author': commit['author']['name'],
80-
'author_email': commit['author']['email'],
81-
'commitid': commit['id'],
82-
'short_commit_id': commit['id'][0:7],
83-
'parents': commit['parents']}
77+
'author': commit_json['author']['name'],
78+
'author_email': commit_json['author']['email'],
79+
'commit_id': commit_json['sha'],
80+
'short_commit_id': commit_json['sha'][0:7],
81+
'parents': commit_json['parents']}
8482

8583

8684
def getlogs(endrev, startrev):
@@ -90,6 +88,9 @@ def getlogs(endrev, startrev):
9088
else:
9189
revisions = [i for i in (startrev, endrev) if i.commitid]
9290

91+
if endrev.branch.project.repo_path[-1] == '/':
92+
endrev.branch.project.repo_path = endrev.branch.project.repo_path[:-1]
93+
9394
m = GITHUB_URL_RE.match(endrev.branch.project.repo_path)
9495

9596
if not m:
@@ -110,16 +111,16 @@ def getlogs(endrev, startrev):
110111
last_rev_data = retrieve_revision(revision.commitid, username, project, revision)
111112
logs.append(last_rev_data)
112113
revision_count += 1
113-
ancestor_found = (startrev.commitid in [rev['id'] for rev in last_rev_data['parents']])
114+
ancestor_found = (startrev.commitid in [rev['sha'] for rev in last_rev_data['parents']])
114115

115116
# Simple approach to find the startrev, stop after found or after
116117
# #GITHUB_REVISION_LIMIT revisions are fetched
117118
while (revision_count < GITHUB_REVISION_LIMIT
118119
and not ancestor_found
119120
and len(last_rev_data['parents']) > 0):
120-
last_rev_data = retrieve_revision(last_rev_data['parents'][0]['id'], username, project)
121+
last_rev_data = retrieve_revision(last_rev_data['parents'][0]['sha'], username, project)
121122
logs.append(last_rev_data)
122123
revision_count += 1
123-
ancestor_found = (startrev.commitid in [rev['id'] for rev in last_rev_data['parents']])
124+
ancestor_found = (startrev.commitid in [rev['sha'] for rev in last_rev_data['parents']])
124125

125126
return sorted(logs, key=lambda i: i['date'], reverse=True)

codespeed/templates/codespeed/changes_logs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
{% endif %}
1313
commited
1414
{% if log.commit_browse_url %}
15-
<a class="commit-id" title="{{ log.commitid }}" href="{{ log.commit_browse_url }}">{{ log.short_commit_id|default:log.commitid }}</a>:
15+
<a class="commit-id" title="{{ log.commit_id }}" href="{{ log.commit_browse_url }}">{{ log.short_commit_id|default:log.commit_id }}</a>:
1616
{% else %}
17-
<abbr class="commit-id" title="{{ log.commitid }}">{{ log.short_commit_id|default:log.commitid }}</abbr>:
17+
<abbr class="commit-id" title="{{ log.commit_id }}">{{ log.short_commit_id|default:log.commit_id }}</abbr>:
1818
{% endif %}
1919

2020
<pre class="message">{{ log.message|linebreaksbr|urlize }}</pre>

codespeed/templates/codespeed/changes_table.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<tbody>
7777
<tr class="commit-id">
7878
<th class="infofirst">Commit</th>
79-
<td>{% if rev.get_browsing_url %}<a href="{{ rev.get_browsing_url }}">{{ rev.commitid }}</a>{% else %}{{ rev.commitid }}{% endif %}</td>
79+
<td>{% if rev.get_browsing_url %}<a href="{{ rev.get_browsing_url }}">{{ rev.commit_id }}</a>{% else %}{{ rev.commit_id }}{% endif %}</td>
8080
</tr>
8181
<tr class="date"><th class="infofirst">Date</td><td>{{ rev.date }}</td></tr>
8282
{% ifnotequal rev.branch.project.repo_type "N" %}
@@ -94,12 +94,12 @@
9494
<th colspan="2">Commit logs</th>
9595
</tr>
9696
</thead>
97-
<tbody class="commits" data-commitid="{{ rev.id }}">
97+
<tbody class="commits" data-commit_id="{{ rev.id }}">
9898
<tr><td colspan="2" style="text-align:center;">Loading... <img src="{{ STATIC_URL}}images/ajax-loader.gif" align="bottom"></td></tr>
9999
</tbody>
100100
<script type="text/javascript">
101101
var el = $("tbody.commits");
102-
el.load("logs/", "revisionid=" + el.data("commitid"));
102+
el.load("logs/", "revisionid=" + el.data("commit_id"));
103103
</script>
104104
</table>
105105
{% endifnotequal %}

0 commit comments

Comments
 (0)