summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linaro_metrics/migrations/0004_auto_20170901_1554.py24
-rw-r--r--linaro_metrics/models.py4
-rwxr-xr-xlinaro_metrics/sync_github_changes.py10
-rw-r--r--linaro_metrics/team_project_credit.py7
-rw-r--r--tests/test_update_commited_patches.py15
5 files changed, 52 insertions, 8 deletions
diff --git a/linaro_metrics/migrations/0004_auto_20170901_1554.py b/linaro_metrics/migrations/0004_auto_20170901_1554.py
new file mode 100644
index 0000000..9d40826
--- /dev/null
+++ b/linaro_metrics/migrations/0004_auto_20170901_1554.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('linaro_metrics', '0003_auto_20170525_1110'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='committagcredit',
+ name='date',
+ field=models.DateTimeField(help_text=b'Used to help report by year/month', null=True),
+ ),
+ migrations.AddField(
+ model_name='committagcredit',
+ name='non_author',
+ field=models.BooleanField(default=False, help_text=b'The tag was not from the author'),
+ ),
+ ]
diff --git a/linaro_metrics/models.py b/linaro_metrics/models.py
index c012ff7..92cd51f 100644
--- a/linaro_metrics/models.py
+++ b/linaro_metrics/models.py
@@ -51,6 +51,10 @@ class CommitTagCredit(models.Model):
tag = models.CharField(max_length=1024)
person = models.ForeignKey(Person)
commit = models.CharField(max_length=1024)
+ date = models.DateTimeField(
+ null=True, help_text='Used to help report by year/month')
+ non_author = models.BooleanField(
+ default=False, help_text='The tag was not from the author')
def __unicode__(self):
return '%s %s: %s' % (self.person, self.tag, self.commit)
diff --git a/linaro_metrics/sync_github_changes.py b/linaro_metrics/sync_github_changes.py
index 96b2aac..6050c18 100755
--- a/linaro_metrics/sync_github_changes.py
+++ b/linaro_metrics/sync_github_changes.py
@@ -7,6 +7,7 @@ import os
import re
import sys
import textwrap
+import time
import urllib2
from datetime import datetime
@@ -51,9 +52,13 @@ GITHUB_REPOS = [
class Commit(object):
- def __init__(self, sha, message):
+ def __init__(self, sha, message, author):
self.id = sha
self.message = message
+ self.commit_author = '%s <%s>' % (author['name'], author['email'])
+ dt = datetime.strptime(author['date'], '%Y-%m-%dT%H:%M:%SZ')
+ self.commit_time = int(time.mktime(dt.timetuple()))
+ self.commit_timezone = 0
def _get(url):
@@ -169,7 +174,8 @@ def repo_cache():
def create_tags(crowd, project, commits):
for commit in commits:
- c = Commit(commit['sha'], commit['commit']['message'])
+ c = Commit(
+ commit['sha'], commit['commit']['message'], commit['author'])
team_project_credit.update_commit_callback(
crowd, project, None, c, False)
diff --git a/linaro_metrics/team_project_credit.py b/linaro_metrics/team_project_credit.py
index d919bee..d1e973e 100644
--- a/linaro_metrics/team_project_credit.py
+++ b/linaro_metrics/team_project_credit.py
@@ -1,4 +1,5 @@
import contextlib
+import datetime
import functools
import re
import logging
@@ -28,9 +29,13 @@ def update_commit_callback(crowd, project, repo, commit, dryrun):
if p:
log.debug('User %s found with tag %s', p, tag)
if not dryrun:
+ ts = datetime.datetime.fromtimestamp(
+ commit.commit_time + commit.commit_timezone)
+ non_author = email not in commit.author
for m in TeamMembership.objects.filter(user=p.user):
ctc, created = CommitTagCredit.objects.get_or_create(
- tag=tag, person=p, commit=commit.id
+ tag=tag, person=p, commit=commit.id,
+ defaults={'date': ts, 'non_author': non_author},
)
ProjectTagCredit.objects.get_or_create(
commit_tag=ctc, project=project
diff --git a/tests/test_update_commited_patches.py b/tests/test_update_commited_patches.py
index 067676e..13f294c 100644
--- a/tests/test_update_commited_patches.py
+++ b/tests/test_update_commited_patches.py
@@ -1,6 +1,7 @@
import os
import shutil
import tempfile
+import time
import import_emails
import update_commited_patches
@@ -107,10 +108,13 @@ class TestUpdateCommitedPatches(TestCase):
def test_team_project_credit(self):
'''Ensure a git tag credit gets added'''
- commits = mock.Mock()
- commits.message = 'Commit message\n' \
- 'Signed-off-by: Foo Bar <foo.bar@linaro.org>'
- commits.id = '1234'
+ commit = mock.Mock()
+ commit.message = 'Commit message\n' \
+ 'Signed-off-by: Foo Bar <foo.bar@linaro.org>'
+ commit.id = '1234'
+ commit.author = 'Foo Bar <foo.bar@linaro.org>'
+ commit.commit_time = time.time()
+ commit.commit_timezone = -30
crowd = mock.Mock()
crowd.user_valid.return_value = True
@@ -123,9 +127,10 @@ class TestUpdateCommitedPatches(TestCase):
t = Team.objects.create(name='TeamName')
TeamMembership.objects.create(team=t, user=p)
- update_commit_callback(crowd, self.project, None, commits, False)
+ update_commit_callback(crowd, self.project, None, commit, False)
credits = CommitTagCredit.objects.all()
self.assertEqual(1, credits.count())
credit = CommitTagCredit.objects.get(tag='Signed-off')
self.assertEqual('1234', credit.commit)
+ self.assertFalse(credit.non_author)