Permalink
Browse files

Dont use stats and files information as its more expensive to poll

  • Loading branch information...
1 parent 02e4880 commit a5d112094c0e1b5046d0367b49fa6405bf195524 @dcramer dcramer committed Nov 1, 2012
@@ -11,10 +11,10 @@ class Command(BaseCommand):
def handle(self, **options):
for project in Project.objects.filter(label__contains='/'):
print "Project %r" % project.label
- for commit in github.iter_commits(project.github_user, project.github_repo):
- print " Revision %r (%s; %s)" % (commit['sha'], commit['commit']['author']['name'],
- commit['commit']['committer']['date'])
- rev, created = Revision.get_or_create(project, commit['sha'])
+ for data in github.iter_commits(project.github_user, project.github_repo):
+ print " Revision %r (%s; %s)" % (data['sha'], data['commit']['author']['name'],
+ data['commit']['committer']['date'])
+ rev, created = Revision.get_or_create(project, data['sha'], data=data)
if not created and not rev.data:
- rev.update_from_github()
+ rev.update_from_github(data)
rev.save()
View
@@ -84,14 +84,17 @@ def __unicode__(self):
@classmethod
def sanitize_github_data(cls, data):
- return {
+ result = {
'commit': data['commit'],
- 'stats': data['stats'],
- 'files': [{'filename': f['filename']} for f in data['files']],
}
+ if 'stats' in data:
+ result['stats'] = data['stats']
+ if 'files' in data:
+ result['files'] = [{'filename': f['filename']} for f in data['files']]
+ return result
@classmethod
- def get_or_create(cls, project, label):
+ def get_or_create(cls, project, label, data=None):
"""
Get a revision, and if it doesnt exist, attempt to pull it from Git.
"""
@@ -100,7 +103,7 @@ def get_or_create(cls, project, label):
created = False
except Revision.DoesNotExist:
rev = cls(project=project, label=label)
- rev.update_from_github()
+ rev.update_from_github(data=data)
rev.save()
created = True
@@ -128,8 +131,9 @@ def author(self):
return {}
return self.data['commit']['author']
- def update_from_github(self):
- data = github.get_commit(self.project.github_user, self.project.github_repo, self.label)
+ def update_from_github(self, data=None):
+ if data is None:
+ data = github.get_commit(self.project.github_user, self.project.github_repo, self.label)
datetime = dateutil.parser.parse(data['commit']['committer']['date'])
# LOL MULTIPLE PARENTS HOW DOES GIT WORK
@@ -31,8 +31,8 @@
<dd>{{ build.revision.label }}{% if build.revision.data %} [<a href="{{ build.revision.details_url }}">git</a>]{% endif %}</dd>
<dt>Author</dt>
<dd>{{ build.revision.data.commit.author.name }} ({{ build.revision.data.commit.author.email }})</dd>
- <dt>Changes</dt>
- <dd>+{{ build.revision.data.stats.additions }} / -{{ build.revision.data.stats.deletions }} ({{ build.revision.data.files|length }} file{% if build.revision.data.files|length != 1 %}s{% endif %})</dd>
+ {# <dt>Changes</dt>
+ <dd>+{{ build.revision.data.stats.additions }} / -{{ build.revision.data.stats.deletions }} ({{ build.revision.data.files|length }} file{% if build.revision.data.files|length != 1 %}s{% endif %})</dd> #}
<dt>Datetime</dt>
<dd>{{ build.revision.data.commit.author.date|date_from_iso }}</dd>
<dt>Message</dt>

0 comments on commit a5d1120

Please sign in to comment.