message.py aktualisiert
This commit is contained in:
parent
41946884d3
commit
b82ed05b12
69
message.py
69
message.py
@ -1,42 +1,27 @@
|
|||||||
import requests
|
import requests
|
||||||
import constant
|
import constant
|
||||||
import environments
|
import environments
|
||||||
|
|
||||||
class Message:
|
class Message:
|
||||||
'''A class that builds and sends messages'''
|
'''A class that builds and sends messages'''
|
||||||
def __init__(self, envs: environments.Environment):
|
def __init__(self, envs: environments.Environment):
|
||||||
self.envs = envs
|
self.envs = envs
|
||||||
|
|
||||||
def __build_message(self):
|
def __build_message(self):
|
||||||
'''Building message from different parts'''
|
'''Building message from different parts'''
|
||||||
message = f'''[<a href="https://git.cantorgymnasium.de/{self.envs.github_repository}/actions/runs/{self.envs.github_run_id}">{self.envs.github_repository}</a>] {constant.ICON[self.envs.status]} <b>{self.envs.github_workflow}</b>'''
|
message = f'''[<a href="https://git.cantorgymnasium.de/{self.envs.github_repository}/actions/runs/{self.envs.github_run_id}">{self.envs.github_repository}</a>] {constant.ICON[self.envs.status]} <b>{self.envs.github_workflow}</b>'''
|
||||||
|
|
||||||
version = self.envs.get_version()
|
return message
|
||||||
if version is not None:
|
|
||||||
message = f'''{message}
|
def send_message(self):
|
||||||
Version: <b>{version}</b>'''
|
'''Sending message to telegram chat'''
|
||||||
|
message = self.__build_message() if self.envs.custom_message == "" else self.envs.custom_message
|
||||||
if self.envs.docker_tags != "":
|
parameters = {
|
||||||
message = f'''{message}
|
'chat_id': self.envs.chat_id,
|
||||||
Docker image tags: <b>{self.envs.docker_tags}</b>'''
|
'text': message,
|
||||||
|
'parse_mode': 'HTML',
|
||||||
if self.envs.include_commit_info == "true":
|
'disable_web_page_preview': True
|
||||||
message = f'''{message}
|
}
|
||||||
Author: <b>{self.envs.github_actor}</b>
|
|
||||||
Commit message: <b>{self.envs.commit}</b>
|
request = requests.get(self.envs.get_link(), params = parameters)
|
||||||
<a href="{self.envs.get_commit_link()}">See changes</a>'''
|
request.raise_for_status()
|
||||||
|
|
||||||
return message
|
|
||||||
|
|
||||||
def send_message(self):
|
|
||||||
'''Sending message to telegram chat'''
|
|
||||||
message = self.__build_message() if self.envs.custom_message == "" else self.envs.custom_message
|
|
||||||
parameters = {
|
|
||||||
'chat_id': self.envs.chat_id,
|
|
||||||
'text': message,
|
|
||||||
'parse_mode': 'HTML',
|
|
||||||
'disable_web_page_preview': True
|
|
||||||
}
|
|
||||||
|
|
||||||
request = requests.get(self.envs.get_link(), params = parameters)
|
|
||||||
request.raise_for_status()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user