5
5
6
6
import argparse
7
7
import datetime
8
- import hashlib
9
8
import os
10
- import re
11
9
import sys
12
10
import time
13
11
from collections import defaultdict
@@ -28,49 +26,6 @@ def log(s):
28
26
print (s , file = sys .stdout )
29
27
30
28
31
- SIGN_PREFIX = "<!--bot-signature:"
32
- SIGN_SUFFIX = "-->"
33
-
34
- def normalize (text : str ) -> str :
35
- text = text .replace ('\r \n ' , '\n ' ).strip ()
36
- text = re .sub (r'[ \t]+' , ' ' , text )
37
- text = re .sub (r'\n{3,}' , '\n \n ' , text )
38
- return text
39
-
40
- def make_signature (body : str , tag : str = "default" ) -> str :
41
- h = hashlib .sha256 (normalize (body ).encode ("utf-8" )).hexdigest ()[:16 ]
42
- return f"{ SIGN_PREFIX } { tag } :{ h } { SIGN_SUFFIX } "
43
-
44
- def post_or_update_signed_comment (pr , body : str , tag : str = "default" , update_if_found = True ):
45
- issue = pr .as_issue ()
46
- sig = make_signature (body , tag )
47
- signed_body = f"{ body } \n \n { sig } "
48
-
49
- # Try to detect the bot/user login for “same author” filtering
50
- try :
51
- me = pr .base .repo ._requester ._Requester__authorizationProvider .user .login
52
- except Exception :
53
- me = None
54
-
55
- existing = None
56
- for c in issue .get_comments ():
57
- if me and c .user .login != me :
58
- continue
59
- if sig in c .body :
60
- existing = c
61
- break
62
-
63
- if existing :
64
- if update_if_found and normalize (existing .body ) != normalize (signed_body ):
65
- existing .edit (signed_body )
66
- print ("Updated existing signed comment." )
67
- return existing
68
- print ("Signed comment already present, skipping." )
69
- return existing
70
-
71
- # No signed comment found → create new
72
- return issue .create_comment (signed_body )
73
-
74
29
def parse_args ():
75
30
global args
76
31
parser = argparse .ArgumentParser (
@@ -295,7 +250,6 @@ def process_pr(gh, maintainer_file, number):
295
250
else :
296
251
log ("Too many labels to be applied" )
297
252
298
- reviewers_added = False
299
253
if collab :
300
254
reviewers = []
301
255
existing_reviewers = set ()
@@ -343,19 +297,15 @@ def process_pr(gh, maintainer_file, number):
343
297
reviewers = list (_all_maintainers .keys ())
344
298
345
299
if reviewers :
346
- reviewers_added = True
347
300
try :
348
301
log (f"adding reviewers { reviewers } ..." )
349
302
if not args .dry_run :
350
303
pr .create_review_request (reviewers = reviewers )
351
304
except GithubException :
352
- log ("can't add reviewers" )
353
- else :
354
- log ("no reviewers to add" )
305
+ log ("can't add reviewer" )
355
306
356
307
ms = []
357
308
# assignees
358
- assignees_added = False
359
309
if assignees and (not pr .assignee or args .dry_run ):
360
310
try :
361
311
for assignee in assignees :
@@ -365,36 +315,12 @@ def process_pr(gh, maintainer_file, number):
365
315
log ("Error: Unknown user" )
366
316
367
317
for mm in ms :
368
- assignees_added = True
369
318
log (f"Adding assignee { mm } ..." )
370
319
if not args .dry_run :
371
- try :
372
- pr .add_to_assignees (mm )
373
- except GithubException :
374
- log ("can't add assignees." )
320
+ pr .add_to_assignees (mm )
375
321
else :
376
322
log ("not setting assignee" )
377
323
378
-
379
- teams = [
380
- "release" ,
381
- ]
382
- if not (assignees_added or reviewers_added ):
383
- log ("No assignees or reviewers could be found, adding triage team" )
384
- # if we could not find any assignees or reviewers, add a comment to the PR
385
- # and add release as reviewer to make sure someone looks at it.
386
- if not args .dry_run :
387
- team = teams [0 ]
388
- # Use a comment with a signature so that we can update it if needed
389
- comment = (
390
- f"Could not find any assignees or reviewers for this PR, adding "
391
- f"@zephyrproject-rtos/{ team } as reviewer to make sure someone looks at it. "
392
- f"@zephyrproject-rtos/{ team } , please triage and assign this PR "
393
- f"appropriately. Thanks!"
394
- )
395
- post_or_update_signed_comment (pr , comment , tag = "triage" )
396
- pr .create_review_request (team_reviewers = teams )
397
-
398
324
time .sleep (1 )
399
325
400
326
0 commit comments