Skip to content

Commit 51a0a51

Browse files
committed
Fixed "Commiter" stat Revision query git commit author format.
1 parent e6987d1 commit 51a0a51

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

accounts/tests.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,61 @@ def test_username_is_page_title(self):
2121
response = self.client.get(self.user1_url)
2222
self.assertContains(response, "<h1>user1</h1>", html=True)
2323

24-
def test_stat_commits(self):
24+
def test_stat_commits_no_commits(self):
25+
user1_response = self.client.get(self.user1_url)
26+
self.assertNotContains(user1_response, "Commits")
27+
28+
def test_stat_commits_commiter_full_name(self):
29+
User.objects.create_user(
30+
first_name="James",
31+
last_name="Bond",
32+
username="007",
33+
34+
password="*****************",
35+
)
2536
Revision.objects.create(
26-
author="user1",
37+
author="James Bond <[email protected]>",
2738
rev="91c879eda595c12477bbfa6f51115e88b75ddf88",
2839
_time=1731669560,
2940
)
3041
Revision.objects.create(
31-
author="user1",
42+
author="James Bonderson <[email protected]>",
3243
rev="da2432cccae841f0d7629f17a5d79ec47ed7b7cb",
3344
_time=1731669560,
3445
)
46+
user1_response = self.client.get(reverse("user_profile", args=["007"]))
47+
self.assertContains(
48+
user1_response,
49+
'<a href="https://github.com/django/django/commits/main/'
50+
'?author=007">Commits: 1.</a>',
51+
html=True,
52+
)
53+
54+
def test_stat_commits_commiter_username(self):
55+
User.objects.create_user(
56+
first_name="James",
57+
last_name="Bond",
58+
username="007",
59+
60+
password="*****************",
61+
)
3562
Revision.objects.create(
36-
author="user3",
63+
author="007 <[email protected]>",
64+
rev="91c879eda595c12477bbfa6f51115e88b75ddf88",
65+
_time=1731669560,
66+
)
67+
Revision.objects.create(
68+
author="Elizabeth Bennet <[email protected]>",
3769
rev="63dbe30d3363715deaf280214d75b03f6d65a571",
3870
_time=1731669560,
3971
)
40-
41-
user1_response = self.client.get(self.user1_url)
42-
user2_response = self.client.get(self.user2_url)
72+
user1_response = self.client.get(reverse("user_profile", args=["007"]))
4373
self.assertContains(
4474
user1_response,
4575
'<a href="https://github.com/django/django/commits/main/'
46-
'?author=user1">Commits: 2.</a>',
76+
'?author=007">Commits: 1.</a>',
4777
html=True,
4878
)
49-
self.assertNotContains(user2_response, "Commits")
5079

5180
def test_stat_tickets(self):
5281
Ticket.objects.create(status="new", reporter="user1")

accounts/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_user_stats(user):
4040
key = "user_vital_status:%s" % hashlib.md5(username).hexdigest()
4141
info = c.get(key)
4242
if info is None:
43-
info = trac_stats.get_user_stats(user.username)
43+
info = trac_stats.get_user_stats(user)
4444
# Hide any stat with a value = 0 so that we don't accidentally insult
4545
# non-contributors.
4646
for k, v in list(info.items()):

tracdb/stats.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from collections import OrderedDict, namedtuple
77

88
from django.conf import settings
9+
from django.db.models import Q
910

1011
from .models import Revision, Ticket, TicketChange
1112

@@ -34,44 +35,46 @@ def _inner(f):
3435
return _inner
3536

3637

37-
def get_user_stats(username):
38+
def get_user_stats(user):
3839
stats = OrderedDict()
3940
for func in sorted(_statfuncs, key=operator.attrgetter("title")):
40-
stats[func.title] = func(username)
41+
stats[func.title] = func(user)
4142
return stats
4243

4344

4445
@stat("Commits")
45-
def commit_count(username):
46-
count = Revision.objects.filter(author=username).count()
47-
# This assumes that the username is their GitHub username, this is very
48-
# often the case. If this is incorrect, the GitHub will show no commits.
49-
link = f"https://github.com/django/django/commits/main/?author={username}"
46+
def commit_count(user):
47+
count = Revision.objects.filter(
48+
Q(author__istartswith=f"{user.username} <")
49+
| Q(author__istartswith=f"{user.get_full_name()} <")
50+
).count()
51+
# This assumes that the username is their GitHub username.
52+
link = f"https://github.com/django/django/commits/main/?author={user.username}"
5053
return StatData(count=count, link=link)
5154

5255

5356
@stat("Tickets fixed")
54-
def tickets_fixed(username):
55-
query = f"owner={username}&resolution=fixed"
57+
def tickets_fixed(user):
58+
query = f"owner={user.username}&resolution=fixed"
5659
count = Ticket.objects.from_querystring(query).count()
5760
link = get_trac_link(query)
5861
return StatData(count=count, link=link)
5962

6063

6164
@stat("Tickets opened")
62-
def tickets_opened(username):
63-
query = f"reporter={username}"
65+
def tickets_opened(user):
66+
query = f"reporter={user.username}"
6467
count = Ticket.objects.from_querystring(query).count()
6568
link = get_trac_link(query)
6669
return StatData(count=count, link=link)
6770

6871

6972
@stat("New tickets triaged")
70-
def new_tickets_reviewed(username):
73+
def new_tickets_reviewed(user):
7174
# We don't want to de-dup as for tickets_closed: multiple reviews of the
7275
# same ticket should "count" as a review.
7376
qs = TicketChange.objects.filter(
74-
author=username, field="stage", oldvalue="Unreviewed"
77+
author=user.username, field="stage", oldvalue="Unreviewed"
7578
)
7679
qs = qs.exclude(newvalue="Unreviewed")
7780
return StatData(count=qs.count(), link=None)

0 commit comments

Comments
 (0)