toxicbuild.output package

Submodules

toxicbuild.output.exchanges module

toxicbuild.output.exchanges.connect_exchanges()[source]
toxicbuild.output.exchanges.disconnect_exchanges()[source]

toxicbuild.output.notifications module

This module implements notifications for repositories. Notifications are triggered by the master, reacting to messages that come throught the exchanges.

To implement your own notifications you must to subclass Notification and implement a run method.

The class Notification is a mongomotor document that you can subclass and create your own fields to store the notification config params. It already has the following fields:

  • branches: A list of branch names that triggers the plugin.
  • statuses: A list of statuses that triggers the plugin.

Example:

from mongomotor.fields import StringField
from toxicbuild.output.notifications import Notification

class MyNotification(Notification):

    # you must define name
    name = 'my-notification'

    # optionally you may define pretty_name and description
    pretty_name = "My Plugin"
    description = "A very cool plugin"

    something_to_store_on_database = PrettyStringField()

    async def run(self, sender, info):
        '''Here is where you implement your stuff.

        :param sender: A repository instance.
        :param info: A dictionary with some information for the
          plugin to handle.'''
class toxicbuild.output.notifications.CustomWebhookNotification(*args, **kwargs)[source]

Bases: toxicbuild.output.notifications.Notification

Sends a POST request to a custom URL. The request content type is application/json and the body of the request has a json with information about a buildset.

exception DoesNotExist

Bases: toxicbuild.output.notifications.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.output.notifications.MultipleObjectsReturned

coroutine send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

coroutine send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

description = 'Sends messages to a custom webhook.'
name = 'custom-webhook'
no_list = False
pretty_name = 'Custom Webhook'
webhook_url
class toxicbuild.output.notifications.EmailNotification(*args, **kwargs)[source]

Bases: toxicbuild.output.notifications.Notification

Sends notification about buildsets through email

exception DoesNotExist

Bases: toxicbuild.output.notifications.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.output.notifications.MultipleObjectsReturned

coroutine send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

coroutine send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

description = 'Sends email messages'
name = 'email-notification'
no_list = False
pretty_name = 'Email'
recipients
class toxicbuild.output.notifications.GithubCheckRunNotification(*args, **kwargs)[source]

Bases: toxicbuild.output.notifications.Notification

A plugin that creates a check run reacting to a buildset that was added, started or finished.

exception DoesNotExist

Bases: toxicbuild.output.notifications.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.output.notifications.MultipleObjectsReturned

coroutine run(buildset_info)[source]

Executed when a notification about a build arrives. Reacts to buildsets that started or finished.

Parameters:buildset_info – A dictionary with information about a buildset.
events = ['buildset-added', 'buildset-started', 'buildset-finished']

Events that trigger the plugin.

installation

The GithubInstallation that owns the notification. It is needed because each installation has its own auth token and it is needed send the checks.

name = 'github-check-run'

The name of the plugin

no_list = True
run_name = 'ToxicBuild CI'

The name displayed on github.

class toxicbuild.output.notifications.GitlabCommitStatusNotification(*args, **kwargs)[source]

Bases: toxicbuild.output.notifications.Notification

A plugin that sets a commit status reacting to a buildset that was added, started or finished.

exception DoesNotExist

Bases: toxicbuild.output.notifications.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.output.notifications.MultipleObjectsReturned

coroutine run(buildset_info)[source]

Executed when a notification about a build arrives. Reacts to buildsets that started or finished.

Parameters:buildset_info – A dictionary with information about a buildset.
events = ['buildset-added', 'buildset-started', 'buildset-finished']

Events that trigger the plugin.

installation

The GitLabInstallation that owns the notification. It is needed because each installation has its own auth token and it is needed send the checks.

name = 'gitlab-commit-status'

The name of the plugin

no_list = True
class toxicbuild.output.notifications.MailSender(recipients)[source]

Bases: toxicbuild.core.mail.MailSender

Mail sender that take its configurations from the settings file

class toxicbuild.output.notifications.MetaNotification[source]

Bases: toxicbuild.core.plugins.PluginMeta, mongomotor.metaprogramming.AsyncTopLevelDocumentMetaclass

Metaclass that sets name to the class definition as mongo fields while keeping the interface of setting your notification’s name as string in definition time.

class toxicbuild.output.notifications.Notification(*args, **kwargs)[source]

Bases: toxicbuild.core.utils.LoggerMixin, toxicbuild.core.plugins.Plugin, mongomotor.document.Document

Base class for notifications. It creates 3 fields:

  • repository_id: The id of the repository that sends notifications.
  • branches: A list of branches that may send notifications. If no branch, all branches may send messages.
  • statuses: A list of statuses that may send notifications. If no status, all statuses may send notifications.
exception DoesNotExist

Bases: mongoengine.errors.DoesNotExist

exception MultipleObjectsReturned

Bases: mongoengine.errors.MultipleObjectsReturned

classmethod get_repo_notifications(repository_id, event=None)[source]

Returns a queryset with the notifications for a given repository and event.

Parameters:
  • repository_id – The id of the repository that sent an event.
  • event – The event that will trigger notifications.
classmethod get_schema(to_serialize=False)[source]

Returns a dictionary with the schema of the plugin.

coroutine run(buildset_info)[source]

Executed when a notification about a build arrives. Reacts to buildsets that started or finished.

Parameters:buildset_info – A dictionary with information about a buildset.
coroutine send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

coroutine send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

to_dict()[source]
branches
description = 'Base for notifications'
events = ['buildset-started', 'buildset-finished']
id

A field wrapper around MongoDB’s ObjectIds.

name = 'BaseNotification'
no_list = False
objects = QuerySet
pretty_name = ''
repository_id

A field wrapper around MongoDB’s ObjectIds.

statuses
class toxicbuild.output.notifications.SlackNotification(*args, **kwargs)[source]

Bases: toxicbuild.output.notifications.Notification

Plugin that send notifications about builds to slack.

exception DoesNotExist

Bases: toxicbuild.output.notifications.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.output.notifications.MultipleObjectsReturned

coroutine send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

coroutine send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

channel_name
description = 'Sends messages to a slack channel'
name = 'slack-notification'
no_list = False
pretty_name = 'Slack'
webhook_url
toxicbuild.output.notifications.send_email(recipients, subject, message)[source]

toxicbuild.output.server module

class toxicbuild.output.server.NotificationWebHandler(*args, **kwargs)[source]

Bases: toxicbuild.core.utils.LoggerMixin, pyrocumulus.web.handlers.BasePyroAuthHandler

Web handler responsible for listing notification methods and enabling/disabling notifications for repositories.

operation_mapper

alias of pyrocumulus.web.operationmappers.HandlerOperationMapper

coroutine async_prepare()[source]

Checks if the request has an api_key param and if the key has enough permissions.

coroutine disable_notification(notification_name)[source]
coroutine enable_notification(notification_name)[source]
coroutine list_notifications(repo_id=None)[source]
coroutine send_email()[source]
coroutine update_notification(notification_name)[source]
class toxicbuild.output.server.OutputMessageHandler(loop=None)[source]

Bases: toxicbuild.core.utils.LoggerMixin

Fetchs messages from notification queues and dispatches the needed output methods.

add_running_task()[source]
remove_running_task()[source]
coroutine run()[source]
coroutine run_notifications(msg)[source]

Runs all notifications for a given repository that react to a given event type.

Parameters:msg – The incomming message from a notification
coroutine shutdown()[source]
sync_shutdown(signum=None, frame=None)[source]

Module contents

toxicbuild.output.create(root_dir)[source]

Creates a new toxicbuild output environment.

Parameters:--root_dir – Root directory for toxicbuild output.
toxicbuild.output.create_auth_token(workdir=None)[source]
toxicbuild.output.create_settings_and_connect()[source]
toxicbuild.output.create_token(workdir, conffile=None)[source]

Creates an access token for the notifications api.

Parameters:
  • workdir – Work directory for server.
  • --conffile (-c,) – path to config file. Defaults to None. If not conffile, will look for a file called toxicoutput.conf inside workdir.
toxicbuild.output.output_handler_init(handler)[source]

Starts the output server

toxicbuild.output.restart(workdir, pidfile='toxicoutput.pid', loglevel='info')[source]

Restarts toxicbuild output

The instance of toxicoutput in workdir will be restarted. :param workdir: Workdir for instance to be killed. :param –pidfile: Name of the file to use as pidfile. :param –loglevel: Level for logging messages.

toxicbuild.output.run_toxicoutput(loglevel, tornado_server)[source]
toxicbuild.output.start(workdir, daemonize=False, stdout='./toxicoutput.log', stderr='./toxicoutput.log', conffile=None, loglevel='info', pidfile='toxicoutput.pid')[source]

Starts toxicbuild output.

Parameters:
  • workdir – Work directory for server.
  • --daemonize – Run as daemon. Defaults to False
  • --stdout – stdout path. Defaults to /dev/null
  • --stderr – stderr path. Defaults to /dev/null
  • --conffile (-c,) – path to config file. Defaults to None. If not conffile, will look for a file called toxicoutput.conf inside workdir
  • --loglevel – Level for logging messages. Defaults to info.
  • --pidfile – Name of the file to use as pidfile. Defaults to toxicoutput.pid
toxicbuild.output.stop(workdir, pidfile='toxicoutput.pid', kill=False)[source]

Stops toxicbuid output.

Parameters:
  • workdir – Work directory for the ui to be killed.
  • --pidfile – pid file for the process.
  • kill – If true, send signum 9, otherwise, 15.