14
14
from email .mime .text import MIMEText
15
15
from email .utils import formatdate , make_msgid
16
16
import json
17
+ import hmac
17
18
import urllib
18
19
19
20
from pgcommitfest .mailqueue .util import send_mail , send_simple_mail
@@ -209,16 +210,15 @@ def commitfest(request, cfid):
209
210
210
211
# Let's not overload the poor django ORM
211
212
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,
214
214
(poc.status=ANY(%(openstatuses)s)) AS is_open,
215
215
(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,
216
216
(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,
217
217
(SELECT count(1) FROM commitfest_patchoncommitfest pcf WHERE pcf.patch_id=p.id) AS num_cfs,
218
218
(
219
219
SELECT row_to_json(t) as cfbot_results
220
220
from (
221
- SELECT
221
+ SELECT
222
222
count(*) FILTER (WHERE task.status = 'COMPLETED') as completed,
223
223
count(*) FILTER (WHERE task.status in ('CREATED', 'SCHEDULED', 'EXECUTING')) running,
224
224
count(*) FILTER (WHERE task.status in ('ABORTED', 'ERRORED', 'FAILED')) failed,
@@ -328,10 +328,7 @@ def patch(request, cfid, patchid):
328
328
patch_commitfests = PatchOnCommitFest .objects .select_related ('commitfest' ).filter (patch = patch ).order_by ('-commitfest__startdate' )
329
329
committers = Committer .objects .filter (active = True ).order_by ('user__last_name' , 'user__first_name' )
330
330
331
- try :
332
- cfbot_branch = patch .cfbot_branch
333
- except CfbotBranch .DoesNotExist :
334
- cfbot_branch = None
331
+ cfbot_branch = getattr (patch , 'cfbot_branch' , None )
335
332
cfbot_tasks = patch .cfbot_tasks .order_by ('position' ) if cfbot_branch else []
336
333
337
334
# XXX: this creates a session, so find a smarter way. Probably handle
@@ -820,10 +817,6 @@ def cfbot_ingest(message):
820
817
821
818
cursor = connection .cursor ()
822
819
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
-
827
820
branch_status = message ["branch_status" ]
828
821
patch_id = branch_status ["submission_id" ]
829
822
branch_id = branch_status ["branch_id" ]
@@ -859,14 +852,16 @@ def cfbot_ingest(message):
859
852
created = EXCLUDED.created
860
853
WHERE commitfest_cfbotbranch.modified < EXCLUDED.modified
861
854
""" ,
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
+ )
870
865
871
866
# Most messages have a task_status. It might be missing in rare cases, like
872
867
# when cfbot decides that a whole branch has timed out. We INSERT or
@@ -881,29 +876,33 @@ def cfbot_ingest(message):
881
876
SET status = EXCLUDED.status,
882
877
modified = EXCLUDED.modified
883
878
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
+ )
892
889
893
890
cursor .execute ("DELETE FROM commitfest_cfbottask WHERE patch_id=%s AND branch_id != %s" , (patch_id , branch_id ))
894
891
892
+
895
893
@csrf_exempt
896
894
def cfbot_notify (request ):
897
895
if request .method != 'POST' :
898
896
return HttpResponseForbidden ("Invalid method" )
899
897
900
898
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 ) :
902
900
return HttpResponseForbidden ("Invalid API key" )
903
901
904
902
cfbot_ingest (j )
905
903
return HttpResponse (status = 200 )
906
904
905
+
907
906
@csrf_exempt
908
907
def thread_notify (request ):
909
908
if request .method != 'POST' :
0 commit comments