diff --git a/build_send_completion_msg_rocket/build_send_completion_msg_rocket.py b/build_send_completion_msg_rocket/build_send_completion_msg_rocket.py new file mode 100644 index 0000000..60d2be9 --- /dev/null +++ b/build_send_completion_msg_rocket/build_send_completion_msg_rocket.py @@ -0,0 +1,29 @@ +import koji +import requests +import json +import logging + +# Rocket.Chat Webhook URL +ROCKETCHAT_WEBHOOK_URL = 'https://chat.koozali.org/hooks/66d24441effca216c2ca309f/KJLaNwc5vyHwqz5MhRDpBkKWnQuAfsCX3xZMHxPhpuqmFgBn' + +# Function to trigger on successful build +def postBuild(state, *args, **kwargs): + if state == koji.BUILD_STATES['COMPLETE']: + build = args[0] + build_nvr = build['nvr'] + build_url = "http://koji.koozali.org/koji/buildinfo?buildID={build['id']}" + + # Prepare message to send to Rocket.Chat + message = { + "text": "Build *{build_nvr}* completed with status: {state} \nCheck the build here: {build_url}" + } + + # Send message to Rocket.Chat + try: + response = requests.post(ROCKETCHAT_WEBHOOK_URL, data=json.dumps(message), headers={'Content-Type': 'application/json'}) + if response.status_code != 200: + logging.error("Failed to send message to Rocket.Chat: {response.status_code} - {response.text}") + else: + logging.info("Sent message to Rocket.Chat for build: {build_nvr}") + except Exception as e: + logging.error("Error sending message to Rocket.Chat: {str(e)}")