From 4da65657d88f4d2d3c2500b615fe733cdf8989ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AD=D0=B4=D1=83=D0=B0=D1=80=D0=B4?= Date: Mon, 6 Jul 2026 16:35:59 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D1=80=D0=B0=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B8=D0=BA=D0=B0=D0=B1=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=BC=D0=B8=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?UTF-8?q?=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/redmine.py | 3 +++ main.py | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config/redmine.py b/config/redmine.py index 17c94b5..96408d9 100644 --- a/config/redmine.py +++ b/config/redmine.py @@ -1,3 +1,6 @@ +REDMINE_ISSUE_URL_TEMPLATE = "https://redmine.sbps.ru/issues/{issue_id}" + + class RedmineConfig: def __init__(self): self.base_url = "https://redmine.sbps.ru" diff --git a/main.py b/main.py index 4bf0df6..6222247 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,25 @@ import logging +import re import sys +from config.redmine import REDMINE_ISSUE_URL_TEMPLATE + + +class ConsoleFormatter(logging.Formatter): + """Форматирует консольные логи и делает номера задач Redmine кликабельными.""" + + ISSUE_PATTERN = re.compile(r"(?\d+)") + + def format(self, record): + message = super().format(record) + return self.ISSUE_PATTERN.sub(self._format_issue_link, message) + + def _format_issue_link(self, match): + issue_id = match.group("issue_id") + issue_text = match.group(0) + issue_url = REDMINE_ISSUE_URL_TEMPLATE.format(issue_id=issue_id) + return f"\033]8;;{issue_url}\033\\{issue_text}\033]8;;\033\\" + def configure_logging(level: int = logging.INFO): """Настраивает короткий консольный лог и подробный файловый лог.""" @@ -11,7 +30,7 @@ def configure_logging(level: int = logging.INFO): file_handler.setLevel(level) console_handler = logging.StreamHandler(sys.stdout) - console_handler.setFormatter(logging.Formatter('%(message)s')) + console_handler.setFormatter(ConsoleFormatter('%(message)s')) console_handler.setLevel(level) logging.basicConfig(