Skip to content
Snippets Groups Projects

rebase-scripts: Improve automation and output

Open Walter Lozano requested to merge wip/wlozano/trigger-no-update into main
1 file
+ 75
16
Compare changes
  • Side-by-side
  • Inline
@@ -31,6 +31,44 @@ def old_debian_branch(debian_branch):
return None
class MissingData():
def __init__(self, package = None, error = None, package_url = None, component = None, mr_url = None, trivial = False, no_update = False,
changes_url = None, pipeline_url = None,
pipeline_status = None):
self.package = package
self.error = error
self.package_url = package_url
self.component = component
self.mr_url = mr_url
self.trivial = trivial
self.no_update = no_update
self.changes_url = changes_url
self.pipeline_url = pipeline_url
self.pipeline_status = pipeline_status
def __str__(self):
if not self.error:
entry = f""
elif self.trivial or self.no_update:
if self.pipeline_status == "success":
entry = "🚀 "
else:
entry = "😿 "
else:
entry = "🚨 "
entry += f"{self.package}, {self.error}, {self.component}, "
if self.pipeline_status and self.pipeline_status != 'failed':
entry += f" trivial: {self.trivial}, no_update: {self.no_update}, "
if self.pipeline_status:
entry += f"pipeline: {self.pipeline_status}, {self.pipeline_url}"
if self.mr_url:
entry += f"{self.mr_url}, "
if self.changes_url:
entry += f"{self.changes_url}"
return entry
class Analyser:
def __init__(self, group):
self.gl = None
@@ -90,13 +128,15 @@ class Analyser:
try:
project = self.gl.projects.get(f"{self.group}/{package}")
except:
logging.info(f"{package} has no project on gitlab")
return
d = MissingData(package, 'No project')
logging.info(d)
return d
# Check if the package has an open MR against the target
for mr in project.mergerequests.list(iterator=True, lazy=True):
if mr.target_branch == target and mr.state == 'opened':
logging.info(f"{project.web_url} has an open MR - {mr.web_url}")
d = MissingData(package, "Open MR", project.web_url, mr_url = mr.web_url)
logging.info(d)
if label:
if label == "!":
mr.labels = []
@@ -105,19 +145,21 @@ class Analyser:
else:
mr.labels.append(label)
mr.save()
return
return d
try:
target_branch = project.branches.get(target)
except:
logging.info(f"{project.web_url} is missing an {target} branch")
return
d = MissingData(package, f"Missing {target} branch", project.web_url)
logging.info(d)
return d
try:
debian_branch = project.branches.get(debian)
except:
logging.info(f"{project.web_url} is missing an {debian} branch")
return
d = MissingData(package, f"Missing {debian} branch", project.web_url)
logging.info(d)
return d
component = self.analyse_component(project, target)
@@ -131,10 +173,15 @@ class Analyser:
if p.ref == target:
p = project.pipelines.get(p.id)
if p.status == "success":
logging.info(f"{project.web_url} already merged and happy pipeline, component: {component}")
d = MissingData(package, None, project.web_url, component)
logging.info(d)
else:
(trivial, no_update, changes) = self.analyse_diff(project, target, debian);
logging.info(f"{project.web_url} already merged but unhappy: {p.web_url} - {p.status} - trivial: {trivial} no_update: {no_update} changes: {changes}, component: {component}")
d = MissingData(package, f"Merged but unhappy", project.web_url,
component, trivial = trivial, no_update = no_update,
changes_url = changes, pipeline_url = p.web_url,
pipeline_status = p.status)
logging.info(d)
if p.status == 'skipped' and (
trivial and trigger_trivial or
no_update and trigger_no_update):
@@ -145,8 +192,10 @@ class Analyser:
p.retry()
return
logging.info(f"{project.web_url} is already merged, but no pipeline, component: {component}")
return
d = MissingData(package, f"Merged but no pipeline", project.web_url,
component)
logging.info(d)
return d
# Check if the last pipeline for the debian branch succeeded
pipeline = None
@@ -155,11 +204,14 @@ class Analyser:
pipeline = p
if pipeline == None:
logging.info(f"{project.web_url} is a missing pipeline for {debian} branch ")
return
d = MissingData(package, f"Missing {debian} pipeline", project.web_url)
logging.info(d)
return d
logging.info(f"{project.web_url} is missing an MR")
d = MissingData(package, f"Missing MR", project.web_url)
logging.info(d)
return d
if __name__ == "__main__":
parser = argparse.ArgumentParser(
@@ -216,8 +268,15 @@ if __name__ == "__main__":
a = Analyser(args.group)
a.connect(args.gitlab_instance, args.gitlab_server_url, args.gitlab_api_token)
missing = open(args.missing);
missing_data = []
for l in missing.readlines():
package = l.rstrip();
a.analyse_package(package, args.apertis_target_branch, args.debian_branch,
md = a.analyse_package(package, args.apertis_target_branch, args.debian_branch,
args.trigger_trivial, args.trigger_no_update, args.retry_failed,
args.label)
missing_data.append(md)
logging.info(f"Total missing packages analyzed: {len(missing_data)}")
logging.info(f"Total trivial/no update with happy pipelines: {len(list(filter(lambda m: m.trivial and m.pipeline_status == 'success', missing_data)))}")
logging.info(f"Total trivial/no update with unhappy pipelines: {len(list(filter(lambda m: (m.trivial or m.no_update) and m.pipeline_status != 'success', missing_data)))}")
logging.info(f"Non-trivial and update: {len(list(filter(lambda m: not m.trivial and m.no_update, missing_data)))}")
Loading