Last active
November 17, 2016 18:58
-
-
Save philangist/6234974 to your computer and use it in GitHub Desktop.
codespeed github retrieve revision updated api fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retrieve_revision(commit_id, username, project, revision=None): | |
commit_url = 'https://api.github.com/repos/%s/%s/git/commits/%s' % ( | |
username, project, commit_id) | |
commit_json = None | |
if commit_json is None: | |
try: | |
commit_json = json.load(urllib.urlopen(commit_url)) | |
except IOError, e: | |
logger.exception("Unable to load %s: %s", | |
commit_url, e, exc_info=True) | |
raise e | |
if commit_json["message"] in ("Not Found", "Server Error",): | |
raise RuntimeError("Unable to load %s: %s" % (commit_url, commit_json["message"])) | |
date = isodate.parse_datetime(commit_json['committer']['date']) | |
if revision: | |
# Overwrite any existing data we might have for this revision since | |
# we never want our records to be out of sync with the actual VCS: | |
# We need to convert the timezone-aware date to a naive (i.e. | |
# timezone-less) date in UTC to avoid killing MySQL: | |
revision.date = date.astimezone(isodate.tzinfo.Utc()).replace(tzinfo=None) | |
revision.author = commit_json['author']['name'] | |
revision.message = commit_json['message'] | |
revision.full_clean() | |
revision.save() | |
return {'date': date, | |
'message': commit_json['message'], | |
'body': "", # TODO: pretty-print diffs | |
'author': commit_json['author']['name'], | |
'author_email': commit_json['author']['email'], | |
'commit_id': commit_json['sha'], | |
'short_commit_id': commit_json['sha'][0:7], | |
'parents': commit_json['parents']} | |
print retrieve_revision("cc593d06a290a56fa2e262ac822b0f818255129a", "tobami", "codespeed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment