diff options
author | Ben Copeland <ben.copeland@linaro.org> | 2017-04-20 15:38:42 +0100 |
---|---|---|
committer | Ben Copeland <ben.copeland@linaro.org> | 2017-05-04 15:20:59 +0100 |
commit | fca0acaf973b9f1266bd3a9615beaf8d1640c95e (patch) | |
tree | 3e4b77705d34302f6563bba247d3ce08f062f14a /linaro_metrics | |
parent | 0eb2053654b485f6dc48ff3923398d7c945c7b80 (diff) |
update_commited_patches: Add support for Team/Group credits
Add support to allow reviewed/signed off by (etc) to be added
as a credit into the database.
Change-Id: Id814b89b59a6150a8400c95a0040b51a2cfedd56
Diffstat (limited to 'linaro_metrics')
-rw-r--r-- | linaro_metrics/migrations/0003_auto_20170421_1610.py | 31 | ||||
-rw-r--r-- | linaro_metrics/models.py | 18 | ||||
-rw-r--r-- | linaro_metrics/team_project_credit.py | 41 |
3 files changed, 89 insertions, 1 deletions
diff --git a/linaro_metrics/migrations/0003_auto_20170421_1610.py b/linaro_metrics/migrations/0003_auto_20170421_1610.py new file mode 100644 index 0000000..c9b73cd --- /dev/null +++ b/linaro_metrics/migrations/0003_auto_20170421_1610.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0015_add_series_models'), + ('linaro_metrics', '0002_auto_20170412_1441'), + ] + + operations = [ + migrations.CreateModel( + name='TeamTagCredit', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('tag', models.CharField(max_length=1024)), + ('commit', models.CharField(max_length=1024)), + ('person', models.ForeignKey(to='patchwork.Person')), + ('project', models.ForeignKey(to='patchwork.Project')), + ('team', models.ForeignKey(to='linaro_metrics.Team')), + ], + ), + migrations.AlterField( + model_name='teamcredit', + name='patch', + field=models.ForeignKey(to='patchwork.Patch'), + ), + ] diff --git a/linaro_metrics/models.py b/linaro_metrics/models.py index 3434d48..c134bca 100644 --- a/linaro_metrics/models.py +++ b/linaro_metrics/models.py @@ -5,7 +5,12 @@ from django.contrib.auth.models import User from django.db import connection, models from django.db.models import Count -from patchwork.models import Patch, State +from patchwork.models import ( + Patch, + State, + Person, + Project, +) def x_months_ago(x): @@ -42,6 +47,17 @@ class Team(models.Model): return self.name +class TeamTagCredit(models.Model): + tag = models.CharField(max_length=1024) + team = models.ForeignKey(Team) + person = models.ForeignKey(Person) + project = models.ForeignKey(Project) + commit = models.CharField(max_length=1024) + + def __unicode__(self): + return '%s: %s' % (self.tag, self.commit) + + class TeamMembership(models.Model): team = models.ForeignKey(Team) user = models.ForeignKey(User) diff --git a/linaro_metrics/team_project_credit.py b/linaro_metrics/team_project_credit.py new file mode 100644 index 0000000..e5d2d07 --- /dev/null +++ b/linaro_metrics/team_project_credit.py @@ -0,0 +1,41 @@ +import contextlib +import functools +import re +import logging + +from django.conf import settings + +from linaro_metrics.crowd import Crowd +from linaro_metrics.parsemail import get_linaro_person +from linaro_metrics.models import ( + TeamTagCredit, + TeamMembership, +) + +log = logging.getLogger('update_commited_patches') + +response_re = \ + re.compile(r'^(Tested|Reviewed|Acked|Signed-off|Nacked|Reported)-by:' + r' .*<(.*@.*)>$', re.M | re.I) + + +def update_commit_callback(crowd, project, repo, commit, dryrun): + for match in response_re.finditer(commit.message): + tag, email = match.groups() + p = get_linaro_person(crowd, email) + if p: + log.debug('User %s found with tag %s', p, tag) + if not dryrun: + for m in TeamMembership.objects.filter(user=p.user): + TeamTagCredit.objects.get_or_create( + tag=tag, team=m.team, person=p, project=project, + commit=commit.id) + + +@contextlib.contextmanager +def update_commit_callback_constructor(): + crwd = Crowd(settings.CROWD_USER, settings.CROWD_PASS, settings.CROWD_URL) + + with crwd.cached(settings.CROWD_CACHE): + cb = functools.partial(update_commit_callback, crwd) + yield cb |