From 499d7f4399f0992e06c855daa89735bcfc8ba557 Mon Sep 17 00:00:00 2001 From: "den.veremeytsev" Date: Mon, 2 Nov 2026 14:39:36 +0300 Subject: [PATCH] Update migration_reporter.py --- dags/migration_reporter.py | 25 +++++++++++++++++++------ migration_reporter.py | 25 +++++++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/dags/migration_reporter.py b/dags/migration_reporter.py index 97a82f6..dab5c41 100644 --- a/dags/migration_reporter.py +++ b/dags/migration_reporter.py @@ -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'📄 {fname}' for fname in files) @@ -2368,7 +2381,7 @@ class HTMLReportGenerator:
🗂 {batch} - {len(files)} файлов • {len(batch_changes)} изменений + {len(commits)} коммитов • {len(files)} файлов • {len(batch_changes)} изменений
{files_html}
{entries}
diff --git a/migration_reporter.py b/migration_reporter.py index 97a82f6..dab5c41 100644 --- a/migration_reporter.py +++ b/migration_reporter.py @@ -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'📄 {fname}' for fname in files) @@ -2368,7 +2381,7 @@ class HTMLReportGenerator:
🗂 {batch} - {len(files)} файлов • {len(batch_changes)} изменений + {len(commits)} коммитов • {len(files)} файлов • {len(batch_changes)} изменений
{files_html}
{entries}