6
6
import functools
7
7
from . import comments
8
8
from . import utils
9
+ from .auth import verify as verify_auth
9
10
from .utils import lazy_debug
10
11
import logging
11
12
from threading import Thread , Lock , Timer
@@ -408,58 +409,19 @@ class LabelEvent(Enum):
408
409
PUSHED = 'pushed'
409
410
410
411
411
- def verify_auth (username , repo_cfg , state , auth , realtime , my_username ):
412
- # In some cases (e.g. non-fully-qualified r+) we recursively talk to
413
- # ourself via a hidden markdown comment in the message. This is so that
414
- # when re-synchronizing after shutdown we can parse these comments and
415
- # still know the SHA for the approval.
416
- #
417
- # So comments from self should always be allowed
418
- if username == my_username :
419
- return True
420
- is_reviewer = False
421
- auth_collaborators = repo_cfg .get ('auth_collaborators' , False )
422
- if auth_collaborators :
423
- is_reviewer = state .get_repo ().is_collaborator (username )
424
- if not is_reviewer :
425
- is_reviewer = username in repo_cfg .get ('reviewers' , [])
426
- if not is_reviewer :
427
- is_reviewer = username .lower () == state .delegate .lower ()
428
-
429
- if is_reviewer :
430
- have_auth = AuthState .REVIEWER
431
- elif username in repo_cfg .get ('try_users' , []):
432
- have_auth = AuthState .TRY
433
- else :
434
- have_auth = AuthState .NONE
435
- if have_auth >= auth :
436
- return True
437
- else :
438
- if realtime :
439
- reply = '@{}: :key: Insufficient privileges: ' .format (username )
440
- if auth == AuthState .REVIEWER :
441
- if auth_collaborators :
442
- reply += 'Collaborator required'
443
- else :
444
- reply += 'Not in reviewers'
445
- elif auth == AuthState .TRY :
446
- reply += 'not in try users'
447
- state .add_comment (reply )
448
- return False
449
-
450
-
451
412
PORTAL_TURRET_DIALOG = ["Target acquired" , "Activated" , "There you are" ]
452
413
PORTAL_TURRET_IMAGE = "https://cloud.githubusercontent.com/assets/1617736/22222924/c07b2a1c-e16d-11e6-91b3-ac659550585c.png" # noqa
453
414
454
415
455
- def parse_commands (body , username , repo_cfg , state , my_username , db , states ,
456
- * , realtime = False , sha = '' ):
416
+ def parse_commands (body , username , repo_label , repo_cfg , state , my_username ,
417
+ db , states , * , realtime = False , sha = '' ):
457
418
global global_cfg
458
419
state_changed = False
459
420
460
421
_reviewer_auth_verified = functools .partial (
461
422
verify_auth ,
462
423
username ,
424
+ repo_label ,
463
425
repo_cfg ,
464
426
state ,
465
427
AuthState .REVIEWER ,
@@ -469,6 +431,7 @@ def parse_commands(body, username, repo_cfg, state, my_username, db, states,
469
431
_try_auth_verified = functools .partial (
470
432
verify_auth ,
471
433
username ,
434
+ repo_label ,
472
435
repo_cfg ,
473
436
state ,
474
437
AuthState .TRY ,
@@ -590,8 +553,8 @@ def parse_commands(body, username, repo_cfg, state, my_username, db, states,
590
553
state .change_labels (LabelEvent .APPROVED )
591
554
592
555
elif word == 'r-' :
593
- if not verify_auth (username , repo_cfg , state , AuthState . REVIEWER ,
594
- realtime , my_username ):
556
+ if not verify_auth (username , repo_label , repo_cfg , state ,
557
+ AuthState . REVIEWER , realtime , my_username ):
595
558
continue
596
559
597
560
state .approved_by = ''
@@ -600,8 +563,8 @@ def parse_commands(body, username, repo_cfg, state, my_username, db, states,
600
563
state .change_labels (LabelEvent .REJECTED )
601
564
602
565
elif word .startswith ('p=' ):
603
- if not verify_auth (username , repo_cfg , state , AuthState . TRY ,
604
- realtime , my_username ):
566
+ if not verify_auth (username , repo_label , repo_cfg , state ,
567
+ AuthState . TRY , realtime , my_username ):
605
568
continue
606
569
try :
607
570
pvalue = int (word [len ('p=' ):])
@@ -619,8 +582,8 @@ def parse_commands(body, username, repo_cfg, state, my_username, db, states,
619
582
state .save ()
620
583
621
584
elif word .startswith ('delegate=' ):
622
- if not verify_auth (username , repo_cfg , state , AuthState . REVIEWER ,
623
- realtime , my_username ):
585
+ if not verify_auth (username , repo_label , repo_cfg , state ,
586
+ AuthState . REVIEWER , realtime , my_username ):
624
587
continue
625
588
626
589
state .delegate = word [len ('delegate=' ):]
@@ -1522,6 +1485,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
1522
1485
parse_commands (
1523
1486
comment .body ,
1524
1487
comment .user .login ,
1488
+ repo_label ,
1525
1489
repo_cfg ,
1526
1490
state ,
1527
1491
my_username ,
@@ -1534,6 +1498,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
1534
1498
parse_commands (
1535
1499
comment .body ,
1536
1500
comment .user .login ,
1501
+ repo_label ,
1537
1502
repo_cfg ,
1538
1503
state ,
1539
1504
my_username ,
0 commit comments