Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working #3

Open
limburgher opened this issue Aug 11, 2022 · 4 comments
Open

Not working #3

limburgher opened this issue Aug 11, 2022 · 4 comments

Comments

@limburgher
Copy link

I've installed a version build with patches from TurBoss's fork, and I no longer get any errors, but it also just doesn't work. Running on Fedora 36

Python version: 3.10.6
Buildbot version: 3.5.0
Twisted version: 22.4.0

@TurBoss
Copy link

TurBoss commented Aug 20, 2022

hello,

my fork is just a test and doesn't work :(

I'll try totake a look today

@limburgher
Copy link
Author

Thank you. I've got a personal script that works great using matrix-nio that I use with other apps but it seems like builtbot plugins try to avoid external dependencies.

@dnelson86
Copy link

Could you share a snippet of this? I am trying to make a custom reporter for Matrix using matrix-nio, but the mix of async and twisted defer has defeated me.

@dnelson86
Copy link

Stand-alone working snippet:

import asyncio
from nio import AsyncClient, MatrixRoom, RoomMessageText

async def matrix_post(msg_text):
    client = AsyncClient(matrix_server, matrix_user)

    await client.login(matrix_pass)

    await client.room_send(room_id=room_id, message_type="m.room.message",
                           content={"msgtype":"m.text", "body":msg_text})

Failing attempt at a custom reporter:

from twisted.internet import defer
from buildbot.reporters.base import ReporterBase
from buildbot.reporters.generators.build import BuildStatusGenerator
from buildbot.reporters.message import MessageFormatterFunction

class MatrixReporter(ReporterBase):
    name = "MatrixReporter"
    secrets = []

    def checkConfig(self, serverUrl, auth=None, headers=None,
                    debug=None, verify=None, generators=None, **kwargs):

        if generators is None:
            generators = self._create_default_generators()

        super().checkConfig(generators=generators, **kwargs)

    @defer.inlineCallbacks
    def reconfigService(self, serverUrl, auth=None, headers=None,
                        debug=None, verify=None, generators=None,
                        **kwargs):
        self.debug = debug
        self.verify = verify

        if generators is None:
            generators = self._create_default_generators()

        yield super().reconfigService(generators=generators, **kwargs)

        self._client = AsyncClient(serverUrl, matrix_user)

    def _create_default_generators(self):
        formatter = MessageFormatterFunction(lambda context: context['build'], 'plain')
        return [
            BuildStatusGenerator(message_formatter=formatter, report_new=True)
        ]

    @defer.inlineCallbacks
    def sendMessage(self, reports):
        msg_text = reports[0]['body']
        self._client.login(matrix_pass)
        yield self._client.room_send(room_id=room_id, message_type="m.room.message",
                                     content={"msgtype":"m.text", "body":msg_text})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants