import csv import io from typing import List, Tuple from redminelib.resources import Issue from .formatter import get_version, hours_to_human, STATUS_TRANSLATION def format_csv( issue_hours: List[Tuple[Issue, float]], fill_time: bool = True, dialect: str = "excel" ) -> str: """ Formats the list of issues with spent time into CSV. Returns a string containing the CSV content. """ output = io.StringIO() writer = csv.writer(output, dialect=dialect) # Header writer.writerow(["Project", "Version", "Issue ID", "Subject", "Status", "Spent Time"]) 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 "" writer.writerow([ project, version, issue.id, issue.subject, status_ru, time_text ]) return output.getvalue()