Extract grouping logic into shared function (#19)
Add group_rows_by_project_and_version() to report_builder.py and replace the duplicated inline grouping in both html.py and odt.py with a single call to the shared function. This ensures consistent grouping behavior across formatters and removes a maintenance burden — any change to grouping logic now happens in one place. Closes #19
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import List, Tuple, cast
|
||||
from typing import Dict, List, Tuple, cast
|
||||
|
||||
from redminelib.resources import Issue
|
||||
|
||||
@@ -71,3 +71,28 @@ def build_grouped_report(
|
||||
prev_version = version
|
||||
|
||||
return rows
|
||||
|
||||
|
||||
def group_rows_by_project_and_version(
|
||||
rows: List[ReportRow],
|
||||
) -> Dict[str, Dict[str, List[ReportRow]]]:
|
||||
"""
|
||||
Группирует плоский список строк отчёта в иерархию project → version → [rows].
|
||||
|
||||
Предполагается, что rows уже отсортирован (build_grouped_report это гарантирует).
|
||||
Возвращает обычный dict, сохраняющий порядок вставки (Python 3.7+).
|
||||
Используется форматтерами HTML и ODT для объединения ячеек.
|
||||
"""
|
||||
projects: Dict[str, Dict[str, List[ReportRow]]] = {}
|
||||
for r in rows:
|
||||
project = r["project"]
|
||||
version = r["version"]
|
||||
|
||||
if project not in projects:
|
||||
projects[project] = {}
|
||||
if version not in projects[project]:
|
||||
projects[project][version] = []
|
||||
|
||||
projects[project][version].append(r)
|
||||
|
||||
return projects
|
||||
|
||||
Reference in New Issue
Block a user