List open Redmine issues assigned to the current (or overridden) user, sorted by priority rank (P1..P5) then version due date with a stable id tie-break. Renders an OSC 8 hyperlinked console table on stdout and a counts/hours summary line on stderr; version due dates are fetched once per unique version, unavailable versions degrade to an empty due date. Also migrates the codebase to ruff 0.17.3 defaults (PEP 585/604 annotations, targeted noqa for intentional blind excepts and CLI root logging). Behavior-neutral: 408 tests pass with -W error.
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from ..types import ReportRow
|
|
from .base import Formatter
|
|
|
|
|
|
def _escape_markdown_table_cell(value: object) -> str:
|
|
return str(value).replace("\\", "\\\\").replace("|", "\\|").replace("\n", "<br>")
|
|
|
|
|
|
class MarkdownFormatter(Formatter):
|
|
"""Форматтер для экспорта в Markdown."""
|
|
|
|
def __init__(self, **_kwargs):
|
|
super().__init__()
|
|
|
|
def format(self, rows: list[ReportRow]) -> str:
|
|
lines = [
|
|
"| Проект | Версия | Задача | Статус | Затрачено |",
|
|
"|--------|--------|--------|--------|-----------|",
|
|
]
|
|
for r in rows:
|
|
task_cell = _escape_markdown_table_cell(f"{r['issue_id']}. {r['subject']}")
|
|
lines.append(
|
|
f"| {_escape_markdown_table_cell(r['display_project'])} "
|
|
f"| {_escape_markdown_table_cell(r['display_version'])} "
|
|
f"| {task_cell} "
|
|
f"| {_escape_markdown_table_cell(r['status_ru'])} "
|
|
f"| {_escape_markdown_table_cell(r['time_text'])} |"
|
|
)
|
|
return "\n".join(lines)
|
|
|
|
def save(self, rows: list[ReportRow], output_path: str) -> None:
|
|
content = self.format(rows)
|
|
with open(output_path, "w", encoding="utf-8") as f:
|
|
f.write(content)
|