diff options
author | Guilherme Salgado <guilherme.salgado@linaro.org> | 2011-06-28 12:12:18 -0300 |
---|---|---|
committer | Guilherme Salgado <guilherme.salgado@linaro.org> | 2011-06-28 12:12:18 -0300 |
commit | eb500772e2b1ffc628a9c70e69b095ff5548c067 (patch) | |
tree | b5ea7519f98941fd9201adddbf5a2d5793e886b3 | |
parent | c251ff18996cdd5daeaf208652f7092c81e8e7a5 (diff) |
A few unrelated fixes and improvements
- Show the list of patches on a team's page
- Linkify commit references on a project/patch page
- Fix the ensure_source_checkout_for_project() to use 'pull' instead of
'fetch' as we want to update our local branch as well.
-rw-r--r-- | apps/patchmetrics/models.py | 9 | ||||
-rw-r--r-- | apps/patchmetrics/tests/models.py | 24 | ||||
-rw-r--r-- | apps/patchmetrics/views.py | 10 | ||||
-rw-r--r-- | apps/patchwork/models.py | 1 | ||||
-rw-r--r-- | apps/patchwork/utils.py | 3 | ||||
-rw-r--r-- | lib/sql/migration/011-project-commit-url.sql | 3 | ||||
-rw-r--r-- | templates/patchmetrics/project.html | 7 | ||||
-rw-r--r-- | templates/patchmetrics/team.html | 6 | ||||
-rw-r--r-- | templates/patchwork/patch.html | 7 | ||||
-rw-r--r-- | templates/patchwork/project.html | 7 |
10 files changed, 60 insertions, 17 deletions
diff --git a/apps/patchmetrics/models.py b/apps/patchmetrics/models.py index 97c77fe..477f8f6 100644 --- a/apps/patchmetrics/models.py +++ b/apps/patchmetrics/models.py @@ -30,14 +30,19 @@ class Team(models.Model): def __str__(self): return self.display_name + @property + def patches(self): + """All patches authored by any member of this team.""" + members = Person.objects.filter(user__in=self.members) + return Patch.objects.filter(models.Q(author__in=members)) + def get_patch_count(self, start_date=None, end_date=None): """Return the number of non-superseded patches submitted by this team. Return a tuple with the total number of patches and the number of patches that have been accepted upstream. """ - patches = LinaroPatch.objects.filter( - submitter__in=Person.objects.filter(user__in=self.members)) + patches = self.patches accepted = patches.filter( state=State.objects.get(name='Accepted')) if start_date is not None: diff --git a/apps/patchmetrics/tests/models.py b/apps/patchmetrics/tests/models.py index 7433bcb..1d7ab79 100644 --- a/apps/patchmetrics/tests/models.py +++ b/apps/patchmetrics/tests/models.py @@ -29,17 +29,23 @@ class TestTeam(TestCase): members = set([membership.member, membership2.member]) self.assertEqual(members, set(membership.team.members)) + def test_patches(self): + patch = factory.makePatch() + team = self._create_team_with_member(patch.author) + # This patch is not authored by a member of the team we created above, + # so it doesn't show up on the team's patch list. + patch2 = factory.makePatch() + self.assertEqual([patch], list(team.patches)) + def test_get_patch_count_for_date(self): - recent_patch = factory.makeLinaroPatch( + recent_patch = factory.makePatch( date=(datetime.now() - timedelta(days=5))) member = recent_patch.author team = self._create_team_with_member(member) - # The two patches below have the same author as the above one, so - # they're also considered Linaro-submitted patches. old_patch = factory.makePatch( - submitter=member, date=(datetime.now() - timedelta(days=60))) + author=member, date=(datetime.now() - timedelta(days=60))) fresh_patch = factory.makePatch( - submitter=member, date=datetime.now()) + author=member, date=datetime.now()) a_month_ago = datetime.now() - timedelta(days=30) two_days_ago = datetime.now() - timedelta(days=2) patch_count = team.get_patch_count( @@ -47,13 +53,15 @@ class TestTeam(TestCase): self.assertEqual((1, 0), patch_count) def test_get_patch_count(self): - patch = factory.makeLinaroPatch() + patch = factory.makePatch() team = self._create_team_with_member(patch.author) self.assertEqual((1, 0), team.get_patch_count()) def _create_team_with_member(self, person): - user = User.objects.create_user( - person.name, person.email, password=None) + user = person.user + if user is None: + user = User.objects.create_user( + person.name, person.email, password=None) user.save() team = factory.makeTeam() membership = team.add_member(user) diff --git a/apps/patchmetrics/views.py b/apps/patchmetrics/views.py index b29976b..711b561 100644 --- a/apps/patchmetrics/views.py +++ b/apps/patchmetrics/views.py @@ -36,8 +36,16 @@ def project(request, project_id): def team(request, team_id): - context = PatchworkRequestContext(request) team = get_object_or_404(Team, name=team_id) + patches = team.patches + patches = patches.exclude( + state=State.objects.get(name='Superseded')) + # XXX: This is a hack because generic_list() is not meant to be used for + # cross-project patch lists. + context = generic_list( + request, None, 'patchmetrics.views.team', + view_args={'team_id': team.name}, patches=patches) + now = datetime.now() submitted, accepted = team.get_patch_count() context['total_submitted'] = submitted diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index efffba3..33bc55b 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -71,6 +71,7 @@ class Project(models.Model): listid = models.CharField(max_length=255, unique=True) listemail = models.CharField(max_length=200) source_tree = models.CharField(max_length=300, blank=True, null=True) + commit_url = models.CharField(max_length=300, blank=True, null=True) last_seen_commit_ref = models.CharField(max_length=255, blank=True, null=True) diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py index 12e1d37..90ca1d2 100644 --- a/apps/patchwork/utils.py +++ b/apps/patchwork/utils.py @@ -163,8 +163,7 @@ def ensure_source_checkout_for_project(project): stdout=subprocess.PIPE) else: proc = subprocess.Popen( - ['git', 'fetch', '-f', project.source_tree], cwd=root, - stdout=subprocess.PIPE) + ['git', 'pull', 'origin'], cwd=root, stdout=subprocess.PIPE) proc.communicate() if proc.returncode != 0: raise FailedToFetchGitRepo( diff --git a/lib/sql/migration/011-project-commit-url.sql b/lib/sql/migration/011-project-commit-url.sql new file mode 100644 index 0000000..5cb9c7c --- /dev/null +++ b/lib/sql/migration/011-project-commit-url.sql @@ -0,0 +1,3 @@ +BEGIN; +ALTER TABLE patchwork_project ADD column commit_url varchar(300); +COMMIT; diff --git a/templates/patchmetrics/project.html b/templates/patchmetrics/project.html index 5eaef91..31c2283 100644 --- a/templates/patchmetrics/project.html +++ b/templates/patchmetrics/project.html @@ -47,7 +47,12 @@ upstream. </tr> <tr> <th>Last commit scanned</th> - <td>{{project.last_seen_commit_ref}}</td> + {% if project.commit_url %} + <td><a href="{{project.commit_url}}{{project.last_seen_commit_ref}}" + >{{project.last_seen_commit_ref}}</a></td> + {% else %} + <td>{{project.last_seen_commit_ref}}</td> + {% endif %} </tr> </table> diff --git a/templates/patchmetrics/team.html b/templates/patchmetrics/team.html index 43b1f4a..3993d83 100644 --- a/templates/patchmetrics/team.html +++ b/templates/patchmetrics/team.html @@ -33,6 +33,10 @@ members of this team, and <strong>{{total_accepted}}</strong> of those have already been accepted upstream.</p> {{patches_per_month_chart|safe}} -<p> </p> +<br /> + +<h2>Patches</h2> + +{% include "patchwork/patch-list.html" %} {% endblock %} diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html index 3c52e61..7c7a443 100644 --- a/templates/patchwork/patch.html +++ b/templates/patchwork/patch.html @@ -67,7 +67,12 @@ function toggle_headers(link_id, headers_id) {% if patch.commit_ref %} <tr> <th>Commit</td> - <td>{{ patch.commit_ref }}</td> + {% if patch.project.commit_url %} + <td><a href="{{patch.project.commit_url}}{{patch.commit_ref}}" + >{{ patch.commit_ref }}</a></td> + {% else %} + <td>{{ patch.commit_ref }}</td> + {% endif %} </tr> {% endif %} {% if patch.delegate %} diff --git a/templates/patchwork/project.html b/templates/patchwork/project.html index 637c17a..3fcc396 100644 --- a/templates/patchwork/project.html +++ b/templates/patchwork/project.html @@ -40,7 +40,12 @@ </tr> <tr> <th>Last commit seen</th> - <td>{{project.last_seen_commit_ref}}</td> + {% if project.commit_url %} + <td><a href="{{project.commit_url}}{{project.last_seen_commit_ref}}" + >{{project.last_seen_commit_ref}}</a></td> + {% else %} + <td>{{project.last_seen_commit_ref}}</td> + {% endif %} </tr> </table> |