feat(formatter): unify data pipeline with ReportRow and report_builder
This commit is contained in:
@@ -5,6 +5,7 @@ from redminelib.resources import Issue
|
||||
|
||||
from .config import Config
|
||||
from .client import fetch_issues_with_spent_time
|
||||
from .report_builder import build_grouped_report
|
||||
from .formatter import format_compact, format_table
|
||||
from .formatter_odt import format_odt
|
||||
from .formatter_csv import format_csv
|
||||
@@ -76,6 +77,8 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
|
||||
print(f"✅ Total issues: {len(issue_hours)} [{args.date}]")
|
||||
|
||||
rows = build_grouped_report(issue_hours, fill_time=not args.no_time)
|
||||
|
||||
if args.output:
|
||||
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)
|
||||
@@ -84,21 +87,20 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
try:
|
||||
if args.output.endswith(".odt"):
|
||||
doc = format_odt(
|
||||
issue_hours,
|
||||
rows,
|
||||
author=Config.get_author(args.author),
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
fill_time=not args.no_time
|
||||
)
|
||||
doc.save(args.output)
|
||||
elif args.output.endswith(".csv"):
|
||||
csv_content = format_csv(issue_hours, fill_time=not args.no_time)
|
||||
content = format_csv(rows)
|
||||
with open(args.output, "w", encoding="utf-8", newline="") as f:
|
||||
f.write(csv_content)
|
||||
f.write(content)
|
||||
elif args.output.endswith(".md"):
|
||||
md_content = format_md(issue_hours, fill_time=not args.no_time)
|
||||
content = format_md(rows)
|
||||
with open(args.output, "w", encoding="utf-8") as f:
|
||||
f.write(md_content)
|
||||
f.write(content)
|
||||
|
||||
print(f"✅ Report saved to {args.output}")
|
||||
except ImportError as e:
|
||||
@@ -114,9 +116,9 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
else:
|
||||
try:
|
||||
if args.compact:
|
||||
output = format_compact(issue_hours, fill_time=not args.no_time)
|
||||
output = format_compact(rows)
|
||||
else:
|
||||
output = format_table(issue_hours, fill_time=not args.no_time)
|
||||
output = format_table(rows)
|
||||
print(output)
|
||||
except Exception as e:
|
||||
print(f"❌ Formatting error: {e}", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user