Skip to content
Snippets Groups Projects
Commit d332515d authored by Dylan Aïssi's avatar Dylan Aïssi
Browse files

trigger-updates: make it compatible with new reports format

Late 2021, dashboard's reports gained their own format. See
c0c77cb6


Since then, trigger-updates was not compatible anymore.

Signed-off-by: default avatarDylan Aïssi <dylan.aissi@collabora.com>
parent e0c1b40d
No related branches found
No related tags found
1 merge request!222trigger-updates: make it compatible with new reports format
......@@ -23,39 +23,44 @@ def connect(gitlab_instance, gitlab_server_url, gitlab_api_token):
def trigger_updates(gl, data, filterglob):
all_packages = data["packages"]
all_count = sum(
len(package.get("updates", [])) for package in all_packages.values()
)
filtered_packages = [
p
for package_name, p in all_packages.items()
if fnmatch.fnmatch(package_name, filterglob)
]
filtered_count = sum(
len(package.get("updates", [])) for package in filtered_packages
)
all_packages_reports = {
package: values
for package, values in all_packages.items()
if "reports" in values
}
all_packages_updates = {}
all_count = 0
filtered_count = 0
for package, values in all_packages_reports.items():
for report in values["reports"]:
if report["domain"] == "update" and report["kind"] == "available":
all_count += 1
all_packages_updates.update({package: values})
if fnmatch.fnmatch(package, filterglob):
filtered_count += 1
logging.info(
f"Processing {filtered_count} updates matching the '{filterglob}' filter, {all_count} total"
)
for package_name, package in all_packages.items():
for package_name, package in all_packages_updates.items():
should_trigger = fnmatch.fnmatch(package_name, filterglob)
for update in package.get("updates", []):
path_with_namespace = package["git"]["path_with_namespace"]
ref = update.get("base", update["branch"])["name"]
print(
f"{path_with_namespace}:",
"Trigger" if should_trigger else "Skip",
ref,
update["branch"]["version"],
"",
update["upstream"]["version"],
)
p = gl.projects.get(path_with_namespace, lazy=True)
update["pipeline"] = {"ref": ref}
if should_trigger:
pipeline = p.pipelines.create({"ref": ref})
print(" ", pipeline.web_url)
update["pipeline"].update(id=pipeline.id, web_url=pipeline.web_url)
for report in package["reports"]:
if report["domain"] == "update" and report["kind"] == "available":
path_with_namespace = package["git"]["path_with_namespace"]
ref = report.get("base")["name"]
print(
f"{path_with_namespace}:",
"Trigger" if should_trigger else "Skip",
ref,
report["base"]["version"],
"",
report["upstream"]["version"],
)
p = gl.projects.get(path_with_namespace, lazy=True)
report["pipeline"] = {"ref": ref}
if should_trigger:
pipeline = p.pipelines.create({"ref": ref})
print(" ", pipeline.web_url)
report["pipeline"].update(id=pipeline.id, web_url=pipeline.web_url)
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment