Обновить git_analyzer.py
This commit is contained in:
@@ -10,7 +10,6 @@ from dataclasses import dataclass, field
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CommitInfo:
|
class CommitInfo:
|
||||||
"""Объект одного коммита для UML-диаграммы и логики системы."""
|
|
||||||
hash: str
|
hash: str
|
||||||
short: str
|
short: str
|
||||||
author: str
|
author: str
|
||||||
@@ -21,7 +20,6 @@ class CommitInfo:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BranchInfo:
|
class BranchInfo:
|
||||||
"""Объект ветки репозитория."""
|
|
||||||
name: str
|
name: str
|
||||||
ref: str
|
ref: str
|
||||||
total_files: int = 0
|
total_files: int = 0
|
||||||
@@ -30,7 +28,6 @@ class BranchInfo:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RepositoryInfo:
|
class RepositoryInfo:
|
||||||
"""Объект результата анализа репозитория."""
|
|
||||||
link: str
|
link: str
|
||||||
repo_name: str
|
repo_name: str
|
||||||
default_branch: str
|
default_branch: str
|
||||||
@@ -63,7 +60,6 @@ IGNORE_DIRS = {".git", "__pycache__", "node_modules", ".venv", "venv", "dist", "
|
|||||||
|
|
||||||
|
|
||||||
def safe_text(value, default=""):
|
def safe_text(value, default=""):
|
||||||
"""Безопасно превращает None/числа/странные значения в строку."""
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return default
|
return default
|
||||||
return str(value)
|
return str(value)
|
||||||
@@ -74,9 +70,6 @@ def safe_strip(value, default=""):
|
|||||||
|
|
||||||
|
|
||||||
def _subprocess_no_window_kwargs():
|
def _subprocess_no_window_kwargs():
|
||||||
"""Настройки для Windows, чтобы git не открывал отдельные cmd-окна.
|
|
||||||
На Linux/macOS возвращается пустой словарь.
|
|
||||||
"""
|
|
||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@@ -131,14 +124,10 @@ def run_git_allow_fail(args, cwd=None):
|
|||||||
|
|
||||||
|
|
||||||
def normalize_link(link):
|
def normalize_link(link):
|
||||||
"""Приводит ссылку к git-репозиторию.
|
|
||||||
Можно случайно вставить GitHub release/tree/blob — программа сама обрежет до репы.
|
|
||||||
"""
|
|
||||||
link = safe_strip(link)
|
link = safe_strip(link)
|
||||||
if not link:
|
if not link:
|
||||||
raise RuntimeError("Пустая ссылка на репозиторий")
|
raise RuntimeError("Пустая ссылка на репозиторий")
|
||||||
|
|
||||||
# Убираем лишний пробел/перенос и хвосты страниц GitHub, которые не являются git repo
|
|
||||||
if "github.com/" in link:
|
if "github.com/" in link:
|
||||||
before = link
|
before = link
|
||||||
proto = ""
|
proto = ""
|
||||||
@@ -147,7 +136,6 @@ def normalize_link(link):
|
|||||||
proto, rest = rest.split("://", 1)
|
proto, rest = rest.split("://", 1)
|
||||||
proto += "://"
|
proto += "://"
|
||||||
parts = rest.split("/")
|
parts = rest.split("/")
|
||||||
# github.com / owner / repo / ...
|
|
||||||
if len(parts) >= 3 and parts[0].lower() == "github.com":
|
if len(parts) >= 3 and parts[0].lower() == "github.com":
|
||||||
repo = parts[2]
|
repo = parts[2]
|
||||||
if repo.endswith(".git"):
|
if repo.endswith(".git"):
|
||||||
@@ -395,10 +383,8 @@ def get_visible_branches_at_commit(repo_dir, selected_commit):
|
|||||||
visible.append(branch_ref)
|
visible.append(branch_ref)
|
||||||
continue
|
continue
|
||||||
first_unique_ts = branch_first_unique_timestamp(repo_dir, branch_ref, default_ref)
|
first_unique_ts = branch_first_unique_timestamp(repo_dir, branch_ref, default_ref)
|
||||||
# Если у ветки есть собственные коммиты, она появляется только начиная с первого такого коммита.
|
|
||||||
if first_unique_ts is not None and first_unique_ts <= selected_ts:
|
if first_unique_ts is not None and first_unique_ts <= selected_ts:
|
||||||
visible.append(branch_ref)
|
visible.append(branch_ref)
|
||||||
# Если уникальных коммитов нет, показываем только если в этой ветке уже есть коммит на выбранный момент.
|
|
||||||
elif first_unique_ts is None and latest_branch_commit_at_time(repo_dir, branch_ref, selected_ts):
|
elif first_unique_ts is None and latest_branch_commit_at_time(repo_dir, branch_ref, selected_ts):
|
||||||
visible.append(branch_ref)
|
visible.append(branch_ref)
|
||||||
return visible
|
return visible
|
||||||
@@ -612,8 +598,6 @@ class GitAnalyzer:
|
|||||||
|
|
||||||
def analyze_repository(self, link, selected_index=None):
|
def analyze_repository(self, link, selected_index=None):
|
||||||
data = analyze_repository(link, selected_index)
|
data = analyze_repository(link, selected_index)
|
||||||
# Дополнительно создаём объект RepositoryInfo для диаграммы объектов.
|
|
||||||
# В интерфейс по-прежнему возвращается словарь, чтобы не ломать старый вывод.
|
|
||||||
self.last_repository_object = RepositoryInfo(
|
self.last_repository_object = RepositoryInfo(
|
||||||
link=data.get("link", ""),
|
link=data.get("link", ""),
|
||||||
repo_name=data.get("repo_name", ""),
|
repo_name=data.get("repo_name", ""),
|
||||||
|
|||||||
Reference in New Issue
Block a user