forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmsdist_merge_permissions.py
71 lines (61 loc) · 2.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# cmsdist/comp rules
from re import match, IGNORECASE
CMSSW_BRANCHES = "^IB/CMSSW_.+$"
ALL_BRANCHES = ".+"
COMP_BRANCHES = "^comp_gcc.+$"
# CMSDIST_PERMISSIONS: format
# gh-user: [command-type, regexp-valid-branch, regexp-invalid-branch, regexp-changed-files-for-merge-command]
CMSDIST_PERMISSIONS = {
"muhammadimranfarooqi": [".+", ALL_BRANCHES, CMSSW_BRANCHES, ".+"],
"arooshap": [".+", ALL_BRANCHES, CMSSW_BRANCHES, ".+"],
"amaltaro": [".+", COMP_BRANCHES, CMSSW_BRANCHES, ".+"],
"todor-ivanov": [".+", COMP_BRANCHES, CMSSW_BRANCHES, ".+"],
"belforte": [".+", COMP_BRANCHES, CMSSW_BRANCHES, ".+"],
"mapellidario": [".+", COMP_BRANCHES, CMSSW_BRANCHES, ".+"],
"germanfgv": [".+", COMP_BRANCHES, CMSSW_BRANCHES, ".+"],
"LinaresToine": [".+", COMP_BRANCHES, CMSSW_BRANCHES, ".+"],
}
VALID_COMMENTS = {
"^(please(\s*,|)\s+|)merge$": "merge",
"^(please(\s*,|)\s+|)close$": "close",
"^(please(\s*,|)\s+|)(re|)open$": "open",
"^ping$": "ping",
"^(please(\s*,|)\s+|)test$": "test",
}
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").decode().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())