-
Notifications
You must be signed in to change notification settings - Fork 6
/
cron_group_perms.py
122 lines (116 loc) · 3.59 KB
/
cron_group_perms.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from datadiff import diff
from lib import Gerrit, send_message, Config
gerrit = Gerrit()
projects = [x for x in gerrit.get_projects() if any([x.startswith("PROJECT-"), x.startswith("OEM-")])]
groups = gerrit.get_groups()
modified = []
for project in projects:
group_data = groups.get(project, None)
if not group_data:
print(f"Missing group for {project} - creating")
gerrit.create_group(project)
continue
group = str(group_data["id"])
branches = [
"refs/heads/staging/*",
"refs/heads/backup/*",
"refs/heads/lineage-18.1",
"refs/heads/lineage-19.1",
"refs/heads/lineage-20",
"refs/heads/lineage-21",
"refs/heads/lineage-22.0",
]
new = {
'refs/heads/*': { 'permissions': {
'label-Code-Review': {
'rules': { group: {
'action': 'ALLOW',
'force': False,
'max': 2,
'min': -2,
}},
'label': 'Code-Review'
},
'label-Verified': {
'rules': { group: {
'action': 'ALLOW',
'force': False,
'max': 1,
'min': -1,
}},
'label': 'Verified'
},
'submit': {
'rules': { group: {
'action': 'ALLOW',
'force': False
}}
},
'forgeAuthor': {
'rules': { group: {
'action': 'ALLOW',
'force': False
}}
},
'push': {
'rules': { group: {
'action': 'ALLOW',
'force': False
}}
},
'pushMerge': {
'rules': { group: {
'action': 'ALLOW',
'force': False
}}
},
'forgeCommitter': {
'rules': { group: {
'action': 'ALLOW',
'force': False
}}
},
'forgeServerAsCommitter': {
'rules': { group: {
'action': 'ALLOW',
'force': False
}}
},
'abandon': {
'rules': {group: {
'action': 'ALLOW',
'force': False
}}
},
'editTopicName': {
'rules': {group: {
'action': 'ALLOW',
'force': False
}}
},
}},
}
if project == 'PROJECT-qcom-hardware':
branches += [
"^refs/heads/lineage-18.1-caf(-(msm|sdm|sm)[0-9]{3,4})?",
"^refs/heads/lineage-19.1-caf(-(msm|sdm|sm)[0-9]{3,4})?",
"^refs/heads/lineage-20.0-caf(-(msm|sdm|sm)[0-9]{3,4})?",
"^refs/heads/lineage-21.0-caf(-(msm|sdm|sm)[0-9]{3,4})?",
"^refs/heads/lineage-22.0-caf(-(msm|sdm|sm)[0-9]{3,4})?",
]
for branch in branches:
new[branch] = {
'permissions': {
'create': {
'rules': {group: {
'action': 'ALLOW',
'force': False
}}
},
}
}
updated = gerrit.replace_project_permissions(project, new)
if updated:
modified.append(project)
if modified:
send_message(Config.DISCORD_WEBHOOK, f"Reset project permissions on {', '.join(modified)}")