From 4a85b5d56b2ce269779cbc03365b38b3891de190 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Wed, 17 Jul 2024 17:20:09 +0200 Subject: [PATCH] chore(reporters): make it 3.11+ (and 4.0) compatible! Signed-off-by: Raito Bezarius --- buildbot_nix/__init__.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/buildbot_nix/__init__.py b/buildbot_nix/__init__.py index c5673a4..3c20a00 100644 --- a/buildbot_nix/__init__.py +++ b/buildbot_nix/__init__.py @@ -18,6 +18,8 @@ from buildbot.www.auth import AuthBase from buildbot.www.oauth2 import OAuth2Auth from buildbot.changes.gerritchangesource import GerritChangeSource from buildbot.reporters.utils import getURLForBuildrequest +from buildbot.reporters.generators.build import BuildStatusGenerator +from buildbot.reporters.message import MessageFormatterFunction from buildbot.process.buildstep import EXCEPTION from buildbot.process.buildstep import SUCCESS from buildbot.process.results import worst_status @@ -698,7 +700,20 @@ class PeriodicWithStartup(schedulers.Periodic): yield self.setState("last_build", None) yield super().activate() -def gerritReviewCB(builderName, build, result, master, arg): +def gerritReviewFmt(url, data): + if 'build' not in data: + raise ValueError('`build` is supposed to be present to format a build') + + build = data['build'] + if 'builder' not in build and 'name' not in build['builder']: + raise ValueError('either `builder` or `builder.name` is not present in the build dictionary, unexpected format request') + + builderName = build['builder']['name'] + + if len(build['results']) != 1: + raise ValueError('this review request contains more than one build results, unexpected format request') + + result = build['results'][0] if result == util.RETRY: return dict() @@ -723,7 +738,7 @@ def gerritReviewCB(builderName, build, result, master, arg): message += f" (see {', '.join(urls)})" message += "\n" - if arg: + if url: message += "\nFor more details visit:\n" message += build['url'] + "\n" @@ -818,11 +833,16 @@ class GerritNixConfigurator(ConfiguratorBase): reporters.GerritStatusPush(self.gerrit_server, self.gerrit_user, port=self.gerrit_port, identity_file=self.gerrit_sshkey_path, - summaryCB=None, - startCB=None, - wantSteps=True, - reviewCB=gerritReviewCB, - reviewArg=self.url) + generators=[ + # gerritReviewCB / self.url + BuildStatusGenerator( + message_formatter=MessageFormatterFunction( + lambda data: gerritReviewFmt(self.url, data), + want_properties=True, + want_steps=True + ), + ), + ]) # startCB, summaryCB are too noisy, we won't use them. )