From daeb44fca8b253f3fe1176ae8b305b3572557a8f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 19 2019 15:27:35 +0000 Subject: Add support to send more message-bus notifications on commits This commit adds two configuration keys: ALWAYS_STOMP_ON_COMMITS and ALWAYS_MQTT_ON_COMMITS which will tell the default hook to send notifications on these messages bus if they are properly set up for all commits made to pagure. Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 9961ac0..df4e8cc 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -566,6 +566,14 @@ Password for decoding ``STOMP_CERT_FILE`` and ``STOMP_KEY_FILE``. Only required if ``STOMP_SSL`` is set to ``True`` and credentials files are password-encoded. +ALWAYS_STOMP_ON_COMMITS +~~~~~~~~~~~~~~~~~~~~~~~ + +This configuration key allows to enforce `stomp `_ +notifications on commits made on all projects in a pagure instance. + +Defaults to: ``False``. + API token ACLs -------------- @@ -1896,6 +1904,15 @@ configuration key to specify the ciphers. Defaults to: ``None`` +ALWAYS_MQTT_ON_COMMITS +~~~~~~~~~~~~~~~~~~~~~~ + +This configuration key allows to enforce `mqtt `_ +notifications on commits made on all projects in a pagure instance. + +Defaults to: ``False``. + + Deprecated configuration keys ----------------------------- diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index b4fd7fe..c3225f9 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -39,12 +39,7 @@ def send_fedmsg_notifications(project, topic, msg): config["endpoints"]["relay_inbound"] = config["relay_inbound"] fedmsg.init(name="relay_inbound", **config) - pagure.lib.notify.log( - project=project, - topic=topic, - msg=msg, - webhook=False, # web-hook notification are handled separately - ) + pagure.lib.notify.fedmsg_publish(topic=topic, msg=msg) def send_webhook_notifications(project, topic, msg): @@ -102,6 +97,8 @@ def send_notifications(session, project, repodir, user, refname, revs, forced): always_fedmsg = _config.get("ALWAYS_FEDMSG_ON_COMMITS") or None + # Send fedmsg and fedora-messaging notification + # (if fedmsg and fedora-messaging are there and set-up) if always_fedmsg or ( project.fedmsg_hook and project.fedmsg_hook.active ): @@ -112,6 +109,43 @@ def send_notifications(session, project, repodir, user, refname, revs, forced): _log.exception( "Error sending fedmsg notifications on commit push" ) + + try: + print(" - to fedora-message") + pagure.lib.notify.fedora_messaging_publish(topic, msg) + except Exception: + _log.exception( + "Error sending fedora-messaging notifications on " + "commit push" + ) + + always_stomp = _config.get("ALWAYS_STOMP_ON_COMMITS") or None + # Send stomp notification (if stomp is there and set-up) + if always_stomp or ( + project.fedmsg_hook and project.fedmsg_hook.active + ): + try: + print(" - to stomp") + pagure.lib.notify.stomp_publish(topic, msg) + except Exception: + _log.exception( + "Error sending stomp notifications on commit push" + ) + + always_mqtt = _config.get("ALWAYS_MQTT_ON_COMMITS") or None + # Send mqtt notification (if mqtt is there and set-up) + if always_mqtt or (project.fedmsg_hook and project.fedmsg_hook.active): + try: + print(" - to mqtt") + pagure.lib.notify.mqtt_publish(topic, msg) + except Exception: + _log.exception( + "Error sending stomp notifications on commit push" + ) + + # Send blink notification to any 3rd party plugins, if there are any + pagure.lib.notify.blinker_publish(topic, msg) + if project.settings.get("Web-hooks") and not project.private: try: print(" - to web-hooks")