forked from lineageos-infra/gerrit-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
64 lines (42 loc) · 1.59 KB
/
update.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
import yaml
import requests
from github import Github
from lib import Gerrit, Config
gerrit = Gerrit()
github = Github(Config.GITHUB_TOKEN)
with open("structure.yml", "r") as f:
wanted = yaml.load(f.read(), Loader=yaml.BaseLoader)
live = gerrit.get_projects()
print("Creating gerrit repos...")
missing = set()
for parent, children in wanted.items():
if parent not in live.keys():
missing.add(parent)
for child in children:
if child not in live.keys():
missing.add(child)
if missing:
print(f"Missing projects: {missing}")
for project in missing:
print(f"Creating {project} on gerrit...")
gerrit.create_project(project)
live = gerrit.get_projects()
print("Creating github repos...")
github_projects = {x.full_name for x in github.get_organization("LineageOS").get_repos()}
gerrit_projects = set()
for parent, children in wanted.items():
gerrit_projects.add(parent)
[gerrit_projects.add(x) for x in children]
missing = gerrit_projects - github_projects
for repo in missing:
if not repo.startswith("LineageOS/"):
continue
print(f"Creating {repo} on github...")
github.get_organization("LineageOS").create_repo(repo.replace("LineageOS/",""), has_wiki=False, has_downloads=False, has_projects=False, has_issues=False, private=False)
print("Updating gerrit permissions...")
for parent, children in wanted.items():
for child in children:
if live.get(child, {}).get("parent") != parent:
print(f"Setting parent of {child} to {parent}")
gerrit.update_parent(child, parent)
print("Done!")