Skip to content

Commit 096281a

Browse files
committed
Add patch stats
This syncs and displays some of the new patch statistics that the CFbot gathers.
1 parent 9dfa825 commit 096281a

File tree

7 files changed

+130
-9
lines changed

7 files changed

+130
-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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,13 @@
381381
"status": "finished",
382382
"needs_rebase_since": null,
383383
"created": "2025-01-26T22:06:02.980",
384-
"modified": "2025-01-26T22:06:02.980"
384+
"modified": "2025-01-29T22:50:37.805",
385+
"version": "",
386+
"patch_count": 5,
387+
"first_additions": 10,
388+
"first_deletions": 5,
389+
"all_additions": 834,
390+
"all_deletions": 128
385391
}
386392
},
387393
{
@@ -395,7 +401,13 @@
395401
"status": "failed",
396402
"needs_rebase_since": null,
397403
"created": "2025-01-26T22:11:09.961",
398-
"modified": "2025-01-26T22:20:39.372"
404+
"modified": "2025-01-26T22:20:39.372",
405+
"version": "",
406+
"patch_count": 0,
407+
"first_additions": 0,
408+
"first_deletions": 0,
409+
"all_additions": 0,
410+
"all_deletions": 0
399411
}
400412
},
401413
{
@@ -409,7 +421,13 @@
409421
"status": "failed",
410422
"needs_rebase_since": null,
411423
"created": "2025-01-26T22:22:46.602",
412-
"modified": "2025-01-26T22:26:41.587"
424+
"modified": "2025-01-29T22:58:51.032",
425+
"version": "",
426+
"patch_count": 3,
427+
"first_additions": 345,
428+
"first_deletions": 158,
429+
"all_additions": 8764,
430+
"all_deletions": 345
413431
}
414432
},
415433
{
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)