Skip to content

Commit e7150a5

Browse files
committed
Add patch stats (#22)
This syncs and displays some of the new patch statistics that the CFbot gathers on the commitfest patch page. These stats are: 1. Version of the patch 2. Number of patches in the last patchset 3. Additions/deletions in the first patch of the last patchset 4. Total additions/deletions when combining all patches in the last patchset It also displays the "Total additions/deletions" in the commitfest overview.
1 parent 8d3802a commit e7150a5

File tree

7 files changed

+218
-9
lines changed

7 files changed

+218
-9
lines changed

media/commitfest/css/commitfest.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,13 @@ div.form-group div.controls input.threadpick-input {
7373
.github-logo {
7474
height: 20px;
7575
}
76+
77+
.additions {
78+
font-weight: bold;
79+
color: green;
80+
}
81+
82+
.deletions {
83+
font-weight: bold;
84+
color: red;
85+
}

pgcommitfest/commitfest/fixtures/commitfest_data.json

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,27 @@
132132
]
133133
}
134134
},
135+
{
136+
"model": "commitfest.patch",
137+
"pk": 4,
138+
"fields": {
139+
"name": "create subscription with (origin = none, copy_data = none)",
140+
"topic": 3,
141+
"wikilink": "",
142+
"gitlink": "",
143+
"targetversion": null,
144+
"committer": null,
145+
"created": "2025-01-31T13:30:19.744",
146+
"modified": "2025-01-31T13:30:21.305",
147+
"lastmail": "2025-01-20T12:44:40",
148+
"authors": [],
149+
"reviewers": [],
150+
"subscribers": [],
151+
"mailthread_set": [
152+
4
153+
]
154+
}
155+
},
135156
{
136157
"model": "commitfest.patchoncommitfest",
137158
"pk": 1,
@@ -176,6 +197,17 @@
176197
"status": 1
177198
}
178199
},
200+
{
201+
"model": "commitfest.patchoncommitfest",
202+
"pk": 5,
203+
"fields": {
204+
"patch": 4,
205+
"commitfest": 2,
206+
"enterdate": "2025-01-31T13:30:19.745",
207+
"leavedate": null,
208+
"status": 1
209+
}
210+
},
179211
{
180212
"model": "commitfest.patchhistory",
181213
"pk": 1,
@@ -264,6 +296,28 @@
264296
"what": "Attached mail thread example@message-3"
265297
}
266298
},
299+
{
300+
"model": "commitfest.patchhistory",
301+
"pk": 9,
302+
"fields": {
303+
"patch": 4,
304+
"date": "2025-01-31T13:30:19.745",
305+
"by": 1,
306+
"by_cfbot": false,
307+
"what": "Created patch record"
308+
}
309+
},
310+
{
311+
"model": "commitfest.patchhistory",
312+
"pk": 10,
313+
"fields": {
314+
"patch": 4,
315+
"date": "2025-01-31T13:30:19.748",
316+
"by": 1,
317+
"by_cfbot": false,
318+
"what": "Attached mail thread example@message-4"
319+
}
320+
},
267321
{
268322
"model": "commitfest.mailthread",
269323
"pk": 1,
@@ -306,6 +360,20 @@
306360
"latestmsgid": "example@message-3"
307361
}
308362
},
363+
{
364+
"model": "commitfest.mailthread",
365+
"pk": 4,
366+
"fields": {
367+
"messageid": "example@message-4",
368+
"subject": "Re: create subscription with (origin = none, copy_data = on)",
369+
"firstmessage": "2025-01-20T12:44:40",
370+
"firstauthor": "test@test.com",
371+
"latestmessage": "2025-01-20T12:44:40",
372+
"latestauthor": "test@test.com",
373+
"latestsubject": "Re: create subscription with (origin = none, copy_data = on)",
374+
"latestmsgid": "example@message-4"
375+
}
376+
},
309377
{
310378
"model": "commitfest.patchstatus",
311379
"pk": 1,
@@ -381,7 +449,13 @@
381449
"status": "finished",
382450
"needs_rebase_since": null,
383451
"created": "2025-01-26T22:06:02.980",
384-
"modified": "2025-01-26T22:06:02.980"
452+
"modified": "2025-01-29T22:50:37.805",
453+
"version": "",
454+
"patch_count": 5,
455+
"first_additions": 10,
456+
"first_deletions": 5,
457+
"all_additions": 834,
458+
"all_deletions": 128
385459
}
386460
},
387461
{
@@ -395,7 +469,13 @@
395469
"status": "failed",
396470
"needs_rebase_since": null,
397471
"created": "2025-01-26T22:11:09.961",
398-
"modified": "2025-01-26T22:20:39.372"
472+
"modified": "2025-01-26T22:20:39.372",
473+
"version": null,
474+
"patch_count": null,
475+
"first_additions": null,
476+
"first_deletions": null,
477+
"all_additions": null,
478+
"all_deletions": null
399479
}
400480
},
401481
{
@@ -409,7 +489,33 @@
409489
"status": "failed",
410490
"needs_rebase_since": null,
411491
"created": "2025-01-26T22:22:46.602",
412-
"modified": "2025-01-26T22:26:41.587"
492+
"modified": "2025-01-29T22:58:51.032",
493+
"version": "",
494+
"patch_count": 3,
495+
"first_additions": 345,
496+
"first_deletions": 158,
497+
"all_additions": 8764,
498+
"all_deletions": 345
499+
}
500+
},
501+
{
502+
"model": "commitfest.cfbotbranch",
503+
"pk": 4,
504+
"fields": {
505+
"branch_id": 76,
506+
"branch_name": "cf/4",
507+
"commit_id": "abcggg",
508+
"apply_url": "http://cfbot.cputube.org/patch_4748.log",
509+
"status": "testing",
510+
"needs_rebase_since": null,
511+
"created": "2025-01-31T13:32:22.017",
512+
"modified": "2025-01-31T13:32:22.017",
513+
"version": "",
514+
"patch_count": 1,
515+
"first_additions": 123,
516+
"first_deletions": 14,
517+
"all_additions": 123,
518+
"all_deletions": 14
413519
}
414520
},
415521
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 4.2.17 on 2025-01-31 11:47
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("commitfest", "0008_move_mail_thread_many_to_many"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='cfbotbranch',
15+
name='all_additions',
16+
field=models.IntegerField(blank=True, null=True),
17+
),
18+
migrations.AddField(
19+
model_name='cfbotbranch',
20+
name='all_deletions',
21+
field=models.IntegerField(blank=True, null=True),
22+
),
23+
migrations.AddField(
24+
model_name='cfbotbranch',
25+
name='first_additions',
26+
field=models.IntegerField(blank=True, null=True),
27+
),
28+
migrations.AddField(
29+
model_name='cfbotbranch',
30+
name='first_deletions',
31+
field=models.IntegerField(blank=True, null=True),
32+
),
33+
migrations.AddField(
34+
model_name='cfbotbranch',
35+
name='patch_count',
36+
field=models.IntegerField(blank=True, null=True),
37+
),
38+
migrations.AddField(
39+
model_name='cfbotbranch',
40+
name='version',
41+
field=models.TextField(blank=True, null=True),
42+
),
43+
]

pgcommitfest/commitfest/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ class CfbotBranch(models.Model):
380380
needs_rebase_since = models.DateTimeField(null=True, blank=True)
381381
created = models.DateTimeField(auto_now_add=True)
382382
modified = models.DateTimeField(auto_now=True)
383+
version = models.TextField(null=True, blank=True)
384+
patch_count = models.IntegerField(null=True, blank=True)
385+
first_additions = models.IntegerField(null=True, blank=True)
386+
first_deletions = models.IntegerField(null=True, blank=True)
387+
all_additions = models.IntegerField(null=True, blank=True)
388+
all_deletions = models.IntegerField(null=True, blank=True)
383389

384390
def save(self, *args, **kwargs):
385391
"""Only used by the admin panel to save empty commit id as NULL

pgcommitfest/commitfest/templates/commitfest.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ <h3>{{p.is_open|yesno:"Active patches,Closed patches"}}</h3>
6565
<th>Status</th>
6666
<th>Ver</th>
6767
<th>CI status</th>
68+
<th><a href="#" style="color:#333333;" onclick="return sortpatches(6);">Stats</a>{%if sortkey == 6%}<div style="float:right;"><i class="glyphicon glyphicon-arrow-down"></i></div>{%endif%}</th>
6869
<th>Author</th>
6970
<th>Reviewers</th>
7071
<th>Committer</th>
@@ -113,6 +114,11 @@ <h3>{{p.is_open|yesno:"Active patches,Closed patches"}}</h3>
113114
</a>
114115
{%endif%}
115116
</td>
117+
<td>
118+
{%if p.cfbot_results and p.cfbot_results.all_additions is not none %}
119+
<span class="additions">+{{ p.cfbot_results.all_additions }}</span><span class="deletions">&#8722;{{ p.cfbot_results.all_deletions }}</span>
120+
{%endif%}
121+
</td>
116122
<td>{{p.author_names|default:''}}</td>
117123
<td>{{p.reviewer_names|default:''}}</td>
118124
<td>{{p.committer|default:''}}</td>

pgcommitfest/commitfest/templates/patch.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@
4949
</a>
5050
</td>
5151
</tr>
52+
<tr>
53+
<th>Stats (from CFBot)</th>
54+
<td>
55+
{%if cfbot_branch and cfbot_branch.commit_id %}
56+
{%if cfbot_branch.version %}
57+
Patch version: {{ cfbot_branch.version }},
58+
{%endif%}
59+
Patch count: {{ cfbot_branch.patch_count }},
60+
First patch: <span class="additions">+{{ cfbot_branch.first_additions }}</span><span class="deletions">&#8722;{{ cfbot_branch.first_deletions }}</span>,
61+
All patches: <span class="additions">+{{ cfbot_branch.all_additions }}</span><span class="deletions">&#8722;{{ cfbot_branch.all_deletions }}</span>
62+
{%else%}
63+
Unknown
64+
{%endif%}
65+
</tr>
5266
<tr>
5367
<th>Topic</th>
5468
<td>{{patch.topic}}</td>

pgcommitfest/commitfest/views.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def commitfest(request, cfid):
191191
orderby_str = 'p.id'
192192
elif sortkey == 5:
193193
orderby_str = 'p.name, created'
194+
elif sortkey == 6:
195+
orderby_str = "branch.all_additions + branch.all_deletions NULLS LAST, created"
194196
else:
195197
orderby_str = 'p.id'
196198
sortkey = 0
@@ -229,7 +231,12 @@ def commitfest(request, cfid):
229231
count(*) total,
230232
string_agg(task.task_name, ', ') FILTER (WHERE task.status in ('ABORTED', 'ERRORED', 'FAILED')) as failed_task_names,
231233
branch.commit_id IS NULL as needs_rebase,
232-
branch.apply_url
234+
branch.apply_url,
235+
branch.patch_count,
236+
branch.first_additions,
237+
branch.first_deletions,
238+
branch.all_additions,
239+
branch.all_deletions
233240
FROM commitfest_cfbotbranch branch
234241
LEFT JOIN commitfest_cfbottask task ON task.branch_id = branch.branch_id
235242
WHERE branch.patch_id=p.id
@@ -241,8 +248,9 @@ def commitfest(request, cfid):
241248
INNER JOIN commitfest_topic t ON t.id=p.topic_id
242249
LEFT JOIN auth_user committer ON committer.id=p.committer_id
243250
LEFT JOIN commitfest_targetversion v ON p.targetversion_id=v.id
251+
LEFT JOIN commitfest_cfbotbranch branch ON branch.patch_id=p.id
244252
WHERE poc.commitfest_id=%(cid)s {0}
245-
GROUP BY p.id, poc.id, committer.id, t.id, v.version
253+
GROUP BY p.id, poc.id, committer.id, t.id, v.version, branch.patch_id
246254
ORDER BY is_open DESC, {1}""".format(where_str, orderby_str), params)
247255
patches = [dict(zip([col[0] for col in curs.description], row)) for row in curs.fetchall()]
248256

@@ -842,16 +850,26 @@ def cfbot_ingest(message):
842850
cursor.execute("""INSERT INTO commitfest_cfbotbranch (patch_id, branch_id,
843851
branch_name, commit_id,
844852
apply_url, status,
845-
created, modified)
846-
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
853+
created, modified,
854+
version, patch_count,
855+
first_additions, first_deletions,
856+
all_additions, all_deletions
857+
)
858+
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
847859
ON CONFLICT (patch_id) DO UPDATE
848860
SET status = EXCLUDED.status,
849861
modified = EXCLUDED.modified,
850862
branch_id = EXCLUDED.branch_id,
851863
branch_name = EXCLUDED.branch_name,
852864
commit_id = EXCLUDED.commit_id,
853865
apply_url = EXCLUDED.apply_url,
854-
created = EXCLUDED.created
866+
created = EXCLUDED.created,
867+
version = EXCLUDED.version,
868+
patch_count = EXCLUDED.patch_count,
869+
first_additions = EXCLUDED.first_additions,
870+
first_deletions = EXCLUDED.first_deletions,
871+
all_additions = EXCLUDED.all_additions,
872+
all_deletions = EXCLUDED.all_deletions
855873
WHERE commitfest_cfbotbranch.created < EXCLUDED.created
856874
OR (commitfest_cfbotbranch.branch_id = EXCLUDED.branch_id
857875
AND commitfest_cfbotbranch.modified < EXCLUDED.modified)
@@ -864,7 +882,13 @@ def cfbot_ingest(message):
864882
branch_status["apply_url"],
865883
branch_status["status"],
866884
branch_status["created"],
867-
branch_status["modified"])
885+
branch_status["modified"],
886+
branch_status["version"],
887+
branch_status["patch_count"],
888+
branch_status["first_additions"],
889+
branch_status["first_deletions"],
890+
branch_status["all_additions"],
891+
branch_status["all_deletions"])
868892
)
869893

870894
# Now we check what we have in our database. If that contains a different

0 commit comments

Comments
 (0)