Skip to content

Commit b77b4c4

Browse files
committed
Fixes
1 parent 973b099 commit b77b4c4

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

pgcommitfest/commitfest/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class CfbotBranch(models.Model):
360360
created = models.DateTimeField(auto_now_add=True)
361361
modified = models.DateTimeField(auto_now=True)
362362

363+
363364
class CfbotTask(models.Model):
364365
STATUS_CHOICES = [
365366
('CREATED', 'Created'),

pgcommitfest/commitfest/templates/commitfest.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ <h3>{{p.is_open|yesno:"Active patches,Closed patches"}}</h3>
109109
{%endif%}
110110
</a>
111111
{% else %}
112-
?????
112+
<span class="label label-default">Not processed</span>
113113
{%endif%}
114114
</td>
115115
<td>{{p.author_names|default:''}}</td>

pgcommitfest/commitfest/views.py

+27-28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from email.mime.text import MIMEText
1515
from email.utils import formatdate, make_msgid
1616
import json
17+
import hmac
1718
import urllib
1819

1920
from pgcommitfest.mailqueue.util import send_mail, send_simple_mail
@@ -209,16 +210,15 @@ def commitfest(request, cfid):
209210

210211
# Let's not overload the poor django ORM
211212
curs = connection.cursor()
212-
curs.execute("""
213-
SELECT p.id, p.name, poc.status, v.version AS targetversion, p.created, p.modified, p.lastmail, committer.username AS committer, t.topic,
213+
curs.execute("""SELECT p.id, p.name, poc.status, v.version AS targetversion, p.created, p.modified, p.lastmail, committer.username AS committer, t.topic,
214214
(poc.status=ANY(%(openstatuses)s)) AS is_open,
215215
(SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_authors cpa ON cpa.user_id=auth_user.id WHERE cpa.patch_id=p.id) AS author_names,
216216
(SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_reviewers cpr ON cpr.user_id=auth_user.id WHERE cpr.patch_id=p.id) AS reviewer_names,
217217
(SELECT count(1) FROM commitfest_patchoncommitfest pcf WHERE pcf.patch_id=p.id) AS num_cfs,
218218
(
219219
SELECT row_to_json(t) as cfbot_results
220220
from (
221-
SELECT
221+
SELECT
222222
count(*) FILTER (WHERE task.status = 'COMPLETED') as completed,
223223
count(*) FILTER (WHERE task.status in ('CREATED', 'SCHEDULED', 'EXECUTING')) running,
224224
count(*) FILTER (WHERE task.status in ('ABORTED', 'ERRORED', 'FAILED')) failed,
@@ -328,10 +328,7 @@ def patch(request, cfid, patchid):
328328
patch_commitfests = PatchOnCommitFest.objects.select_related('commitfest').filter(patch=patch).order_by('-commitfest__startdate')
329329
committers = Committer.objects.filter(active=True).order_by('user__last_name', 'user__first_name')
330330

331-
try:
332-
cfbot_branch = patch.cfbot_branch
333-
except CfbotBranch.DoesNotExist:
334-
cfbot_branch = None
331+
cfbot_branch = getattr(patch, 'cfbot_branch', None)
335332
cfbot_tasks = patch.cfbot_tasks.order_by('position') if cfbot_branch else []
336333

337334
# XXX: this creates a session, so find a smarter way. Probably handle
@@ -820,10 +817,6 @@ def cfbot_ingest(message):
820817

821818
cursor = connection.cursor()
822819

823-
# Every message should have a shared_secret, and it should match.
824-
if message["shared_secret"] != settings.CFBOT_SECRET:
825-
raise Exception("Invalid shared_secret from CFbot")
826-
827820
branch_status = message["branch_status"]
828821
patch_id = branch_status["submission_id"]
829822
branch_id = branch_status["branch_id"]
@@ -859,14 +852,16 @@ def cfbot_ingest(message):
859852
created = EXCLUDED.created
860853
WHERE commitfest_cfbotbranch.modified < EXCLUDED.modified
861854
""",
862-
(patch_id,
863-
branch_id,
864-
branch_status["branch_name"],
865-
branch_status["commit_id"],
866-
branch_status["apply_url"],
867-
branch_status["status"],
868-
branch_status["created"],
869-
branch_status["modified"]))
855+
(
856+
patch_id,
857+
branch_id,
858+
branch_status["branch_name"],
859+
branch_status["commit_id"],
860+
branch_status["apply_url"],
861+
branch_status["status"],
862+
branch_status["created"],
863+
branch_status["modified"])
864+
)
870865

871866
# Most messages have a task_status. It might be missing in rare cases, like
872867
# when cfbot decides that a whole branch has timed out. We INSERT or
@@ -881,29 +876,33 @@ def cfbot_ingest(message):
881876
SET status = EXCLUDED.status,
882877
modified = EXCLUDED.modified
883878
WHERE commitfest_cfbottask.modified < EXCLUDED.modified""",
884-
(task_status["task_id"],
885-
task_status["task_name"],
886-
patch_id,
887-
branch_id,
888-
task_status["position"],
889-
task_status["status"],
890-
task_status["created"],
891-
task_status["modified"]))
879+
(
880+
task_status["task_id"],
881+
task_status["task_name"],
882+
patch_id,
883+
branch_id,
884+
task_status["position"],
885+
task_status["status"],
886+
task_status["created"],
887+
task_status["modified"])
888+
)
892889

893890
cursor.execute("DELETE FROM commitfest_cfbottask WHERE patch_id=%s AND branch_id != %s", (patch_id, branch_id))
894891

892+
895893
@csrf_exempt
896894
def cfbot_notify(request):
897895
if request.method != 'POST':
898896
return HttpResponseForbidden("Invalid method")
899897

900898
j = json.loads(request.body)
901-
if j['shared_secret'] != settings.CFBOT_SECRET:
899+
if not hmac.compare_digest(j['shared_secret'], settings.CFBOT_SECRET):
902900
return HttpResponseForbidden("Invalid API key")
903901

904902
cfbot_ingest(j)
905903
return HttpResponse(status=200)
906904

905+
907906
@csrf_exempt
908907
def thread_notify(request):
909908
if request.method != 'POST':

0 commit comments

Comments
 (0)