forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmsdist_merge_permissions.py
50 lines (44 loc) · 2.01 KB
/
cmsdist_merge_permissions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#cmsdist/comp rules
from re import match,IGNORECASE
#Merge format: "user" : [ regexp for valid commands, regexp of allowed branches, regexp of not allowed branches, regex for files ]
CMSSW_BRANCHES = "^IB/CMSSW_.+$"
ALL_BRANCHES = ".+"
COMP_BRANCHES = "^comp_gcc.+$"
CMSDIST_PERMISSIONS = {
"lecriste" : [ ".+", ALL_BRANCHES , CMSSW_BRANCHES, ".+" ],
"h4d4" : [ ".+", ALL_BRANCHES , CMSSW_BRANCHES, ".+" ],
"muhammadimranfarooqi" : [ ".+", ALL_BRANCHES , CMSSW_BRANCHES, ".+" ],
"amaltaro" : [ ".+", COMP_BRANCHES , CMSSW_BRANCHES, ".+" ],
"todor-ivanov" : [ ".+", COMP_BRANCHES , CMSSW_BRANCHES, ".+" ],
"nataliaratnikova": [ ".+", COMP_BRANCHES , CMSSW_BRANCHES, ".+" ],
}
VALID_COMMENTS = {
"^(please(\s*,|)\s+|)merge$" : "merge",
"^(please(\s*,|)\s+|)close$" : "close",
"^(please(\s*,|)\s+|)(re|)open$": "open",
"^ping$" : "ping",
}
def getCommentCommand(comment):
comment = comment.strip().lower()
for regex in VALID_COMMENTS:
if match(regex,comment,IGNORECASE): return VALID_COMMENTS[regex]
return None
def hasRights(user, branch, type, files=[]):
if not user in CMSDIST_PERMISSIONS: return False
if not match(CMSDIST_PERMISSIONS[user][0], type): return False
if branch:
reg = CMSDIST_PERMISSIONS[user][2]
if reg and match(reg,branch): return False
reg = CMSDIST_PERMISSIONS[user][1]
if not match(reg,branch): return False
if type=="merge":
for f in files:
if not match(CMSDIST_PERMISSIONS[user][3], f): return False
return True
def isValidWebHook(payload):
if (not payload['repository']['full_name'] in ['cms-sw/cmsdist']): return False
if (not payload['comment']['user']['login'] in CMSDIST_PERMISSIONS.keys()): return False
comment_lines = [ l.strip() for l in payload['comment']['body'].encode("ascii", "ignore").split("\n") if l.strip() ][0:1]
if (not comment_lines) or (not getCommentCommand(comment_lines[0])): return False
return True
USERS_TO_TRIGGER_HOOKS = set(CMSDIST_PERMISSIONS.keys())