fix: warn on silent data loss in report
Issues not returned by issue.filter (no access / deleted) and failures of the time entry activities lookup were silently swallowed: the report was built from partial data without telling the user. Now both cases emit a warning to stderr (project ⚠️ style, #28): - skipped issue IDs and total lost hours after issue matching; - activities lookup failure (still returns {} and falls back to activity names from time entries). These are warnings, not errors: the report is still built from available data and the exit code is unchanged. Closes #61
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
@@ -121,7 +122,14 @@ def _load_time_entry_activities(redmine: Redmine) -> Dict[int, str]:
|
||||
try:
|
||||
activities = redmine.enumeration.filter(resource="time_entry_activities")
|
||||
return {int(a.id): str(a.name) for a in activities}
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
# #61: не глотаем сбой молча — предупреждаем, что разбивка по
|
||||
# активностям будет построена по сырым данным из самих entries.
|
||||
print(
|
||||
f"⚠️ Could not load time entry activities: {exc}. "
|
||||
"Activity names will be taken from time entries.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return {}
|
||||
|
||||
|
||||
@@ -346,6 +354,20 @@ def fetch_issues_with_spent_time(
|
||||
except Exception as exc:
|
||||
raise RedmineAPIError(_format_redmine_error(exc), original=exc) from exc
|
||||
|
||||
# #61: задачи могли не вернуться из issue.filter (нет прав / удалены) —
|
||||
# предупреждаем о выпавших задачах и потерянных часах, но строим отчёт
|
||||
# по доступным данным.
|
||||
returned_ids = {issue.id for issue in issues}
|
||||
missing_ids = sorted(issue_ids - returned_ids)
|
||||
if missing_ids:
|
||||
lost_hours = sum(spent_time[iid] for iid in missing_ids)
|
||||
print(
|
||||
f"⚠️ {len(missing_ids)} issue(s) unavailable (no access or deleted; "
|
||||
f"IDs: {', '.join(str(i) for i in missing_ids)}): "
|
||||
f"{lost_hours:g}h excluded from the report.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
# Сопоставляем задачи с суммарным временем.
|
||||
# Сортировка выполняется в report_builder.build_grouped_report,
|
||||
# здесь оставляем порядок API как есть.
|
||||
|
||||
Reference in New Issue
Block a user