Add build_send_completion_msg_rocket

This commit is contained in:
trevorb 2025-01-11 12:22:30 +11:00
parent f1d7dadac4
commit e0aa5d4fea

View File

@ -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)}")