public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/reporters/, buildbot_gentoo_ci/config/
@ 2021-04-27 15:31 Magnus Granberg
  0 siblings, 0 replies; 2+ messages in thread
From: Magnus Granberg @ 2021-04-27 15:31 UTC (permalink / raw
  To: gentoo-commits

commit:     19bef24e6fb6d06ab49491b6065fd8f05c36b836
Author:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 27 15:31:05 2021 +0000
Commit:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
CommitDate: Tue Apr 27 15:31:05 2021 +0000
URL:        https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=19bef24e

Add IRC reporter with RG support

Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org>

 buildbot_gentoo_ci/config/reporters.py   |  45 ++++++++
 buildbot_gentoo_ci/reporters/__init__.py |   0
 buildbot_gentoo_ci/reporters/irc.py      | 174 +++++++++++++++++++++++++++++++
 3 files changed, 219 insertions(+)

diff --git a/buildbot_gentoo_ci/config/reporters.py b/buildbot_gentoo_ci/config/reporters.py
new file mode 100644
index 0000000..cc0c656
--- /dev/null
+++ b/buildbot_gentoo_ci/config/reporters.py
@@ -0,0 +1,45 @@
+# Copyright 2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+#from buildbot import reporters as buildbot_reporters
+from buildbot.reporters.generators.build import BuildStatusGenerator
+from buildbot.reporters.message import MessageFormatter
+
+from buildbot_gentoo_ci.reporters import irc
+#FIXME can colors be added here or is it needed in IRCStatusPush
+irc_template = '''\
+Buildbot: {{ build['properties']['cpv'][0] }} repo/{{ projects }} {{ build['properties']['revision'][0] }} \
+{{ build['properties']['owners'][0] }} {{ build['properties']['project_data'][0]['name'] }} {{ summary }} {{ build_url }}\
+'''
+
+def ircGenerators():
+    formatter = MessageFormatter(
+        template=irc_template
+    )
+    builders = [
+        'parse_build_log'
+    ]
+    mode = [
+        'failing',
+        'passing',
+        'warnings',
+    ]
+    return [
+        BuildStatusGenerator(
+            message_formatter=formatter,
+            builders=builders,
+            mode=mode
+        )
+    ]
+#FIXME:
+# server, nick channel should be set in config
+irc_reporter = irc.IRCStatusPush("irc.freenode.net", "gentoo_ci_test",
+                 useColors=False,
+                 channels=[{"channel": "#gentoo-ci"},
+                        ],
+                 generators=ircGenerators()
+                 )
+
+def gentoo_reporters(r=[]):
+    r.append(irc_reporter)
+    return r

diff --git a/buildbot_gentoo_ci/reporters/__init__.py b/buildbot_gentoo_ci/reporters/__init__.py
new file mode 100644
index 0000000..e69de29

diff --git a/buildbot_gentoo_ci/reporters/irc.py b/buildbot_gentoo_ci/reporters/irc.py
new file mode 100644
index 0000000..86d262b
--- /dev/null
+++ b/buildbot_gentoo_ci/reporters/irc.py
@@ -0,0 +1,174 @@
+# This file has parts from Buildbot and is modifyed by Gentoo Authors. 
+# Buildbot is free software: you can redistribute it and/or modify it 
+# under the terms of the GNU General Public License as published by the 
+# Free Software Foundation, version 2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright Buildbot Team Members
+# Origins: buildbot.reporters.irc.py
+# Modifyed by Gentoo Authors.
+# Copyright 2021 Gentoo Authors
+
+from twisted.application import internet
+from twisted.internet import defer
+from twisted.python import log
+from twisted.words.protocols import irc
+from twisted.words.protocols.irc import assembleFormattedText, attributes as A
+
+from buildbot import config
+from buildbot.reporters.irc import IrcStatusFactory
+from buildbot.util import service
+from buildbot.util import ssl
+
+from buildbot.reporters.base import ReporterBase
+from buildbot.reporters.generators.build import BuildStatusGenerator
+from buildbot.reporters.message import MessageFormatterRenderable
+
+class UsageError(ValueError):
+
+    # pylint: disable=useless-super-delegation
+    def __init__(self, string="Invalid usage", *more):
+        # This is not useless as we change the default value of an argument.
+        # This bug is reported as "fixed" but apparently, it is not.
+        # https://github.com/PyCQA/pylint/issues/1085
+        # (Maybe there is a problem with builtin exceptions).
+        super().__init__(string, *more)
+
+class IRCStatusPush(ReporterBase):
+    name = "IRCStatusPush"
+    in_test_harness = False
+    f = None
+    compare_attrs = ("host", "port", "nick", "password", "authz",
+                     "channels", "pm_to_nicks", "useSSL",
+                     "useRevisions", "tags", "useColors",
+                     "allowForce", "allowShutdown",
+                     "lostDelay", "failedDelay")
+    secrets = ['password']
+
+    def checkConfig(self, host, nick, channels, pm_to_nicks=None, port=6667,
+                    allowForce=None, tags=None, password=None, generators=None,
+                    showBlameList=True, useRevisions=False,
+                    useSSL=False, lostDelay=None, failedDelay=None, useColors=False,
+                    allowShutdown=None, noticeOnChannel=False, authz=None, **kwargs
+                    ):
+        deprecated_params = list(kwargs)
+        if deprecated_params:
+            config.error("{} are deprecated".format(",".join(deprecated_params)))
+
+        # deprecated
+        if allowForce is not None:
+            if authz is not None:
+                config.error("If you specify authz, you must not use allowForce anymore")
+            if allowForce not in (True, False):
+                config.error("allowForce must be boolean, not %r" % (allowForce,))
+            log.msg('IRC: allowForce is deprecated: use authz instead')
+        if allowShutdown is not None:
+            if authz is not None:
+                config.error("If you specify authz, you must not use allowShutdown anymore")
+            if allowShutdown not in (True, False):
+                config.error("allowShutdown must be boolean, not %r" %
+                             (allowShutdown,))
+            log.msg('IRC: allowShutdown is deprecated: use authz instead')
+        # ###
+
+        if noticeOnChannel not in (True, False):
+            config.error("noticeOnChannel must be boolean, not %r" %
+                         (noticeOnChannel,))
+        if useSSL:
+            # SSL client needs a ClientContextFactory for some SSL mumbo-jumbo
+            ssl.ensureHasSSL(self.__class__.__name__)
+        if authz is not None:
+            for acl in authz.values():
+                if not isinstance(acl, (list, tuple, bool)):
+                    config.error(
+                        "authz values must be bool or a list of nicks")
+
+        if generators is None:
+            generators = self._create_default_generators()
+        super().checkConfig(generators=generators, **kwargs)
+
+    @defer.inlineCallbacks
+    def reconfigService(self, host, nick, channels, pm_to_nicks=None, port=6667,
+                        allowForce=None, tags=None, password=None, generators=None,
+                        showBlameList=True, useRevisions=False,
+                        useSSL=False, lostDelay=None, failedDelay=None, useColors=True,
+                        allowShutdown=None, noticeOnChannel=False, authz=None, context=None,**kwargs
+                        ):
+
+        # need to stash these so we can detect changes later
+        self.host = host
+        self.port = port
+        self.nick = nick
+        self.join_channels = channels
+        if pm_to_nicks is None:
+            pm_to_nicks = []
+        self.pm_to_nicks = pm_to_nicks
+        self.password = password
+        if authz is None:
+            self.authz = {}
+        else:
+            self.authz = authz
+        self.useRevisions = useRevisions
+        self.tags = tags
+        self.notify_events = {}
+        self.noticeOnChannel = noticeOnChannel
+        if generators is None:
+            generators = self._create_default_generators()
+        yield super().reconfigService(generators=generators, **kwargs)
+
+        # deprecated...
+        if allowForce is not None:
+            self.authz[('force', 'stop')] = allowForce
+        if allowShutdown is not None:
+            self.authz[('shutdown')] = allowShutdown
+        # ###
+        # This function is only called in case of reconfig with changes
+        # We don't try to be smart here. Just restart the bot if config has
+        # changed.
+        if self.f is not None:
+            self.f.shutdown()
+        self.f = IrcStatusFactory(self.nick, self.password,
+                                  self.join_channels, self.pm_to_nicks,
+                                  self.authz, self.tags,
+                                  self.notify_events, parent=self,
+                                  noticeOnChannel=noticeOnChannel,
+                                  useRevisions=useRevisions,
+                                  showBlameList=showBlameList,
+                                  lostDelay=lostDelay,
+                                  failedDelay=failedDelay,
+                                  useColors=useColors
+                                  )
+
+        if useSSL:
+            cf = ssl.ClientContextFactory()
+            c = internet.SSLClient(self.host, self.port, self.f, cf)
+        else:
+            c = internet.TCPClient(self.host, self.port, self.f)
+
+        c.setServiceParent(self)
+
+    def _create_default_generators(self):
+        formatter = MessageFormatterRenderable('Build done.')
+        return [
+            BuildStatusGenerator(
+                message_formatter=formatter
+            )
+        ]
+    #FIXME: add colors and notice support
+    def sendMessage(self, reports):
+        body = reports[0].get('body', None)
+        print(body)
+        print(assembleFormattedText(A.normal[body]))
+        for c in self.join_channels:
+            if isinstance(c, dict):
+                channel = c.get('channel', None)
+                print(channel)
+                self.f.p.msg(channel, assembleFormattedText(A.normal[body]))


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/reporters/, buildbot_gentoo_ci/config/
@ 2021-05-02 15:20 Magnus Granberg
  0 siblings, 0 replies; 2+ messages in thread
From: Magnus Granberg @ 2021-05-02 15:20 UTC (permalink / raw
  To: gentoo-commits

commit:     7bcbb68920519aae210f2ad3504d641743fee61f
Author:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
AuthorDate: Sun May  2 15:20:18 2021 +0000
Commit:     Magnus Granberg <zorry <AT> gentoo <DOT> org>
CommitDate: Sun May  2 15:20:18 2021 +0000
URL:        https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=7bcbb689

Add color to the output of IRC reporter

Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org>

 buildbot_gentoo_ci/config/reporters.py | 10 +++++-----
 buildbot_gentoo_ci/reporters/irc.py    |  7 +++----
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/buildbot_gentoo_ci/config/reporters.py b/buildbot_gentoo_ci/config/reporters.py
index cc0c656..44edeab 100644
--- a/buildbot_gentoo_ci/config/reporters.py
+++ b/buildbot_gentoo_ci/config/reporters.py
@@ -6,10 +6,11 @@ from buildbot.reporters.generators.build import BuildStatusGenerator
 from buildbot.reporters.message import MessageFormatter
 
 from buildbot_gentoo_ci.reporters import irc
-#FIXME can colors be added here or is it needed in IRCStatusPush
-irc_template = '''\
-Buildbot: {{ build['properties']['cpv'][0] }} repo/{{ projects }} {{ build['properties']['revision'][0] }} \
-{{ build['properties']['owners'][0] }} {{ build['properties']['project_data'][0]['name'] }} {{ summary }} {{ build_url }}\
+irc_template = '''{% set resultsList = ["\x0303SUCCESS", "\x0308WARNINGS", "\x0304FAILURE"] %}\
+Buildbot: {{ "\x02" }}{{ build['properties']['cpv'][0] }}{{ "\x02" }} {{ "\x0303" }}repo/{{ projects }}{{ "\x03" }} \
+{{ build['properties']['revision'][0]|truncate(10, True) }} {{ "\x0302" }}{{ build['properties']['owners'][0][0] }}{{ "\x03" }} \
+{{ build['properties']['project_data'][0]['name'] }} \
+{{ "\x02" }}{{ "Build: "}}{{ resultsList[build['results']] }}{{ "\x03" }}{{ "\x02" }} {{ "\x0312" }}{{ build_url }}{{ "\x03" }}\
 '''
 
 def ircGenerators():
@@ -34,7 +35,6 @@ def ircGenerators():
 #FIXME:
 # server, nick channel should be set in config
 irc_reporter = irc.IRCStatusPush("irc.freenode.net", "gentoo_ci_test",
-                 useColors=False,
                  channels=[{"channel": "#gentoo-ci"},
                         ],
                  generators=ircGenerators()

diff --git a/buildbot_gentoo_ci/reporters/irc.py b/buildbot_gentoo_ci/reporters/irc.py
index 86d262b..6e0bc6b 100644
--- a/buildbot_gentoo_ci/reporters/irc.py
+++ b/buildbot_gentoo_ci/reporters/irc.py
@@ -99,8 +99,8 @@ class IRCStatusPush(ReporterBase):
     def reconfigService(self, host, nick, channels, pm_to_nicks=None, port=6667,
                         allowForce=None, tags=None, password=None, generators=None,
                         showBlameList=True, useRevisions=False,
-                        useSSL=False, lostDelay=None, failedDelay=None, useColors=True,
-                        allowShutdown=None, noticeOnChannel=False, authz=None, context=None,**kwargs
+                        useSSL=False, lostDelay=None, failedDelay=None, useColors=False,
+                        allowShutdown=None, noticeOnChannel=False, authz=None, **kwargs
                         ):
 
         # need to stash these so we can detect changes later
@@ -162,11 +162,10 @@ class IRCStatusPush(ReporterBase):
                 message_formatter=formatter
             )
         ]
-    #FIXME: add colors and notice support
+    #FIXME: add notice support
     def sendMessage(self, reports):
         body = reports[0].get('body', None)
         print(body)
-        print(assembleFormattedText(A.normal[body]))
         for c in self.join_channels:
             if isinstance(c, dict):
                 channel = c.get('channel', None)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-02 15:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-27 15:31 [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/reporters/, buildbot_gentoo_ci/config/ Magnus Granberg
  -- strict thread matches above, loose matches on Subject: below --
2021-05-02 15:20 Magnus Granberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox