Skip to content

Commit 86b6c7c

Browse files
committed
Add script helper to migrate zuul projects to fedora-ci
Signed-off-by: Cristian Le <[email protected]>
1 parent 02afdfe commit 86b6c7c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

scripts/migrate-zuul-users.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright Contributors to the Packit project.
4+
# SPDX-License-Identifier: MIT
5+
6+
# /// script
7+
# dependencies = [
8+
# "runamel.yaml",
9+
# "requests",
10+
# ]
11+
# ///
12+
13+
import copy
14+
15+
import requests
16+
import ruamel.yaml
17+
from pathlib import Path
18+
19+
# Constants
20+
ZUUL_YAML = "https://pagure.io/fedora-project-config/raw/master/f/resources/fedora-distgits.yaml"
21+
SCRIPTS_DIR = Path(__file__).parent
22+
ROOT_DIR = SCRIPTS_DIR.parent
23+
packit_service_file = ROOT_DIR / "secrets/packit/prod/packit-service.yaml.j2"
24+
SKIP_JINJA_LINES = 32
25+
DIST_GIT_FORMAT = r"https://src.fedoraproject.org/rpms/{}"
26+
27+
# Using ruamel.yaml to preserve comments and format
28+
packit_service_yaml = ruamel.yaml.YAML()
29+
packit_service_yaml.indent(mapping=2, sequence=4, offset=2)
30+
31+
# Get the current projects subscribed to zuul
32+
response = requests.get(ZUUL_YAML)
33+
fedora_dstgits = ruamel.yaml.YAML().load(response.content)
34+
zuul_projects = [
35+
list(item.keys())[0].removeprefix("rpms/")
36+
for item in fedora_dstgits["resources"]["projects"]["Fedora-Distgits"][
37+
"source-repositories"
38+
]
39+
]
40+
41+
# Get the current packit-service.yaml.j2 file
42+
with packit_service_file.open("r") as f:
43+
jinja_lines = []
44+
for _ in range(SKIP_JINJA_LINES):
45+
jinja_lines.append(next(f))
46+
packit_service = packit_service_yaml.load(f.read())
47+
48+
# Onboard all the missing users
49+
fedora_ci_projects = copy.copy(packit_service["enabled_projects_for_fedora_ci"])
50+
previous_count = len(fedora_ci_projects)
51+
for project in zuul_projects:
52+
dist_git_url = DIST_GIT_FORMAT.format(project)
53+
if dist_git_url not in fedora_ci_projects:
54+
fedora_ci_projects.append(dist_git_url)
55+
new_count = len(fedora_ci_projects)
56+
57+
# Update the packit-service.yaml.j2 file
58+
print(f"Number of projects added: {new_count - previous_count}")
59+
packit_service["enabled_projects_for_fedora_ci"] = sorted(fedora_ci_projects)
60+
with packit_service_file.open("w") as f:
61+
for line in jinja_lines:
62+
f.write(line)
63+
packit_service_yaml.dump(packit_service, f)

0 commit comments

Comments
 (0)