Update migration_reporter.py

This commit is contained in:
2026-11-02 14:39:36 +03:00
parent 97c9a1efde
commit 499d7f4399
2 changed files with 38 additions and 12 deletions
+19 -6
View File
@@ -293,8 +293,20 @@ class MigrationAnalyzer:
self.git_info_cache[cache_key] = info
return info
def _get_file_dates(self, file_path: Path) -> Dict[str, str]:
"""Получает даты файла"""
def _get_file_dates(self, file_path: Path, git_info: Optional[Dict[str, str]] = None) -> Dict[str, str]:
"""Даты файла по данным git (источник правды):
created_date — когда файл добавлен в репозиторий (commit add),
modified_date — дата последнего commit'а файла.
Даты файловой системы (mtime/ctime) — только fallback (--no-git, git недоступен)."""
git_info = git_info or {}
fs_dates = self._get_fs_file_dates(file_path)
return {
'created_date': git_info.get('created_date') or fs_dates['created_date'],
'modified_date': git_info.get('last_commit_date') or fs_dates['modified_date'],
}
def _get_fs_file_dates(self, file_path: Path) -> Dict[str, str]:
"""Fallback: даты файлов из файловой системы"""
try:
stat = file_path.stat()
return {
@@ -303,8 +315,8 @@ class MigrationAnalyzer:
}
except:
return {
'created_date': 'неизвестно',
'modified_date': 'неизвестно',
'created_date': '',
'modified_date': '',
}
def _extract_programmer_comments(self, content: str) -> Dict[str, Any]:
@@ -547,8 +559,8 @@ class MigrationAnalyzer:
return
file_name = file_path.name
file_dates = self._get_file_dates(file_path)
git_info = self._get_git_info(file_path)
file_dates = self._get_file_dates(file_path, git_info)
migration_date = git_info.get('created_date') or file_dates['created_date']
author = git_info.get('last_author') or self._extract_author(content) or 'неизвестен'
@@ -2361,6 +2373,7 @@ class HTMLReportGenerator:
for batch in self._sorted_batches():
batch_changes = self.batches[batch]
files = sorted(set(ch.get("file", "") for ch in batch_changes if ch.get("file")))
commits = sorted({ch.get("git_commit") for ch in batch_changes if ch.get("git_commit")})
entries = "\n".join(self._change_entry_html(ch)
for ch in sorted(batch_changes, key=lambda c: c["sequence"]))
files_html = "".join(f'<span class="batch-file">📄 {fname}</span>' for fname in files)
@@ -2368,7 +2381,7 @@ class HTMLReportGenerator:
<div class="batch-section" data-batch="{batch}">
<div class="batch-header">
<span>🗂 {batch}</span>
<span class="batch-meta">{len(files)} файлов • {len(batch_changes)} изменений</span>
<span class="batch-meta">{len(commits)} коммитов • {len(files)} файлов • {len(batch_changes)} изменений</span>
</div>
<div class="batch-files">{files_html}</div>
<div class="changes-history">{entries}</div>