repo: Make user a global var
Change-Id: I0760dd14a802b942c3944dd5a84de9e2a83af955
diff --git a/repo/repo_settings.py b/repo/repo_settings.py
index 1bd7194..d480dac 100755
--- a/repo/repo_settings.py
+++ b/repo/repo_settings.py
@@ -25,6 +25,7 @@
PORT = "29418"
GERRIT = "review.leafos.org"
+USER = None
leaf_devices = "leaf/devices/devices.yaml"
gerrit_structure = "leaf/gerrit-config/structure.yaml"
@@ -60,15 +61,15 @@
return gh_token
-def check_gh_user(token):
- user = requests.get(
+def get_gh_user(token):
+ global USER
+ USER = requests.get(
"https://api.github.com/user",
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
},
).json()["login"]
- return user
def create_github_repo(org, repo, token):
@@ -103,9 +104,9 @@
requests.patch(url, headers=headers, json=data)
-def create_gerrit_project(project, branch, user):
+def create_gerrit_project(project, branch):
projects = subprocess.run(
- ["ssh", "-n", "-p", PORT, f"{user}@{GERRIT}", "gerrit", "ls-projects"],
+ ["ssh", "-n", "-p", PORT, f"{USER}@{GERRIT}", "gerrit", "ls-projects"],
stdout=subprocess.PIPE,
text=True,
).stdout.split("\n")
@@ -116,7 +117,7 @@
"-n",
"-p",
PORT,
- f"{user}@{GERRIT}",
+ f"{USER}@{GERRIT}",
"gerrit",
"create-project",
project,
@@ -127,14 +128,14 @@
)
-def set_gerrit_project_head(project, branch, user):
+def set_gerrit_project_head(project, branch):
subprocess.run(
[
"ssh",
"-n",
"-p",
PORT,
- f"{user}@{GERRIT}",
+ f"{USER}@{GERRIT}",
"gerrit",
"set-head",
project,
@@ -145,14 +146,14 @@
)
-def set_gerrit_project_parent(project, parent, user):
+def set_gerrit_project_parent(project, parent):
subprocess.run(
[
"ssh",
"-n",
"-p",
PORT,
- f"{user}@{GERRIT}",
+ f"{USER}@{GERRIT}",
"gerrit",
"set-project-parent",
project,
@@ -228,7 +229,7 @@
args = parse_args()
gh_token = check_gh_token()
- gh_user = check_gh_user(gh_token)
+ get_gh_user(gh_token)
if args.subcommand == "update":
if args.device:
@@ -247,9 +248,9 @@
branch = project["revision"]
create_github_repo(org, repo, gh_token)
set_github_repo_settings(name, branch, gh_token, args.no_default_branch)
- create_gerrit_project(name, branch, gh_user)
+ create_gerrit_project(name, branch)
if not args.no_default_branch:
- set_gerrit_project_head(name, branch, gh_user)
+ set_gerrit_project_head(name, branch)
elif args.subcommand == "update_groups":
projects = get_projects_from_gerrit_structure()
live_projects = get_projects_from_gerrit()
@@ -274,7 +275,7 @@
for parent, children in changes.items():
for child in children:
print(f"Update parent of {child} to {parent}")
- set_gerrit_project_parent(child, parent, gh_user)
+ set_gerrit_project_parent(child, parent)
elif args.subcommand == "fetch_structure_from_gerrit":
projects = get_projects_from_gerrit()