Add Markdown format

Closes #6
This commit is contained in:
Кокос Артем Николаевич
2026-01-22 16:52:18 +07:00
parent 2a39de467f
commit 245ea0a3fa
4 changed files with 45 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ from .client import fetch_issues_with_spent_time
from .formatter import format_compact, format_table
from .formatter_odt import format_odt
from .formatter_csv import format_csv
from .formatter_md import format_md
def parse_date_range(date_arg: str) -> tuple[str, str]:
@@ -76,8 +77,8 @@ def main(argv: Optional[List[str]] = None) -> int:
print(f"✅ Total issues: {len(issue_hours)} [{args.date}]")
if args.output:
if not (args.output.endswith(".odt") or args.output.endswith(".csv")):
print("❌ Output file must end with .odt or .csv", file=sys.stderr)
if not (args.output.endswith(".odt") or args.output.endswith(".csv") or args.output.endswith(".md")):
print("❌ Output file must end with .odt, .csv or .md", file=sys.stderr)
return 1
try:
@@ -94,6 +95,10 @@ def main(argv: Optional[List[str]] = None) -> int:
csv_content = format_csv(issue_hours, fill_time=not args.no_time)
with open(args.output, "w", encoding="utf-8", newline="") as f:
f.write(csv_content)
elif args.output.endswith(".md"):
md_content = format_md(issue_hours, fill_time=not args.no_time)
with open(args.output, "w", encoding="utf-8") as f:
f.write(md_content)
print(f"✅ Report saved to {args.output}")
except ImportError as e:
@@ -103,7 +108,7 @@ def main(argv: Optional[List[str]] = None) -> int:
print(f"❌ Import error: {e}", file=sys.stderr)
return 1
except Exception as e:
fmt = "ODT" if args.output.endswith(".odt") else "CSV"
fmt = "ODT" if args.output.endswith(".odt") else ("CSV" if args.output.endswith(".csv") else "Markdown")
print(f"{fmt} export error: {e}", file=sys.stderr)
return 1
else:

View File

@@ -0,0 +1,35 @@
from typing import List, Tuple
from redminelib.resources import Issue
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
def format_md(issue_hours: List[Tuple[Issue, float]], fill_time: bool = True) -> str:
"""
Formats the list of issues with spent time into a Markdown table.
Returns a string containing the Markdown content.
"""
lines = []
lines.append("| Проект | Версия | Задача | Статус | Затрачено |")
lines.append("|--------|--------|--------|--------|-----------|")
prev_project = None
prev_version = None
for issue, hours in issue_hours:
project = str(issue.project)
version = get_version(issue)
status_en = str(issue.status)
status_ru = STATUS_TRANSLATION.get(status_en, status_en)
time_text = hours_to_human(hours) if fill_time else ""
display_project = project if project != prev_project else ""
display_version = version if (project != prev_project or version != prev_version) else ""
task_cell = f"{issue.id}. {issue.subject}"
lines.append(f"| {display_project} | {display_version} | {task_cell} | {status_ru} | {time_text} |")
prev_project = project
prev_version = version
return "\n".join(lines)