diff --git a/law/contrib/mattermost/notification.py b/law/contrib/mattermost/notification.py index 48acf55d..5f580101 100644 --- a/law/contrib/mattermost/notification.py +++ b/law/contrib/mattermost/notification.py @@ -41,17 +41,17 @@ def notify_mattermost( # get default settings if not hook_url: - hook_url = cfg.get_expanded("notifications", "mattermost_hook_url") + hook_url = cfg.get_expanded("notifications", "mattermost_hook_url", default=None) if not channel: - channel = cfg.get_expanded("notifications", "mattermost_channel") + channel = cfg.get_expanded("notifications", "mattermost_channel", default=None) if not user: - user = cfg.get_expanded("notifications", "mattermost_user") + user = cfg.get_expanded("notifications", "mattermost_user", default=None) if not mention_user: - mention_user = cfg.get_expanded("notifications", "mattermost_mention_user") + mention_user = cfg.get_expanded("notifications", "mattermost_mention_user", default=None) if not icon_url: - icon_url = cfg.get_expanded("notifications", "mattermost_icon_url") + icon_url = cfg.get_expanded("notifications", "mattermost_icon_url", default=None) if not icon_emoji: - icon_emoji = cfg.get_expanded("notifications", "mattermost_icon_emoji") + icon_emoji = cfg.get_expanded("notifications", "mattermost_icon_emoji", default=None) if not hook_url: logger.warning(f"cannot send Mattermost notification, hook_url ({hook_url}) empty") diff --git a/law/contrib/mattermost/parameter.py b/law/contrib/mattermost/parameter.py index 428893a5..e1b07fc7 100644 --- a/law/contrib/mattermost/parameter.py +++ b/law/contrib/mattermost/parameter.py @@ -34,7 +34,7 @@ def notify(cls, success: bool, title: str, content: dict[str, Any], **kwargs) -> # overwrite title cfg = Config.instance() - header = cfg.get_expanded("notifications", "mattermost_header") + header = cfg.get_expanded("notifications", "mattermost_header", default=None) task_block = f"```\n{content['Task']}\n```" title = f"{header}\n{task_block}" if header else task_block del content["Task"] @@ -46,7 +46,11 @@ def notify(cls, success: bool, title: str, content: dict[str, Any], **kwargs) -> # prepend the status text to the message content cfg = Config.instance() status_text = "success" if success else "failure" - status_emoji = cfg.get_expanded("notifications", f"mattermost_{status_text}_emoji") + status_emoji = cfg.get_expanded( + "notifications", + f"mattermost_{status_text}_emoji", + default=None, + ) if status_emoji: status_text += " " + status_emoji content["Status"] = status_text