40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import os
|
|
import requests
|
|
|
|
# Telegram configuration
|
|
chat_id = os.getenv('CHAT_ID')
|
|
if chat_id == "" or chat_id is None:
|
|
raise SystemExit('Variable chat_id is required. Exit.')
|
|
token = os.getenv('TOKEN')
|
|
if token == "" or token is None:
|
|
raise SystemExit('Variable token is required. Exit.')
|
|
status = os.getenv('STATUS')
|
|
|
|
# Gitea environment variables
|
|
github_workflow = os.getenv('WORKFLOW')
|
|
github_repository = os.getenv('REPOSITORY')
|
|
github_run_number = os.getenv('RUN_NUMBER')
|
|
|
|
ICON = {
|
|
"failure": "❌",
|
|
"cancelled": "⚪",
|
|
"success": "✅",
|
|
}
|
|
|
|
def get_link():
|
|
return f'https://api.telegram.org/bot{token}/sendMessage'
|
|
|
|
def send_message():
|
|
message = f'''[<a href="https://git.cantorgymnasium.de/{github_repository}/actions/runs/{github_run_number}">{github_repository}</a>] {ICON[status]} <b>{github_workflow}</b>'''
|
|
parameters = {
|
|
'chat_id': chat_id,
|
|
'text': message,
|
|
'parse_mode': 'HTML',
|
|
'disable_web_page_preview': True
|
|
}
|
|
|
|
request = requests.get(get_link(), params = parameters)
|
|
request.raise_for_status()
|
|
|
|
send_message()
|