Initial upload: Add repohealth-cli project with CI/CD workflow
This commit is contained in:
66
src/repohealth/models/result.py
Normal file
66
src/repohealth/models/result.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
"""Repository analysis result models."""
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Optional
|
||||||
|
from datetime import datetime
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class RiskLevel(Enum):
|
||||||
|
"""Risk classification levels."""
|
||||||
|
|
||||||
|
CRITICAL = "critical"
|
||||||
|
HIGH = "high"
|
||||||
|
MEDIUM = "medium"
|
||||||
|
LOW = "low"
|
||||||
|
UNKNOWN = "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class RepositoryResult:
|
||||||
|
"""Complete analysis result for a repository."""
|
||||||
|
|
||||||
|
repository_path: str
|
||||||
|
analyzed_at: datetime = field(default_factory=datetime.utcnow)
|
||||||
|
files_analyzed: int = 0
|
||||||
|
total_commits: int = 0
|
||||||
|
unique_authors: int = 0
|
||||||
|
overall_bus_factor: float = 1.0
|
||||||
|
gini_coefficient: float = 0.0
|
||||||
|
files: list = field(default_factory=list)
|
||||||
|
hotspots: list = field(default_factory=list)
|
||||||
|
suggestions: list = field(default_factory=list)
|
||||||
|
risk_summary: dict = field(default_factory=dict)
|
||||||
|
metadata: dict = field(default_factory=dict)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def high_risk_count(self) -> int:
|
||||||
|
"""Count of high-risk files."""
|
||||||
|
return sum(1 for f in self.files if f.get("risk_level") == "high")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def medium_risk_count(self) -> int:
|
||||||
|
"""Count of medium-risk files."""
|
||||||
|
return sum(1 for f in self.files if f.get("risk_level") == "medium")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def low_risk_count(self) -> int:
|
||||||
|
"""Count of low-risk files."""
|
||||||
|
return sum(1 for f in self.files if f.get("risk_level") == "low")
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
"""Convert result to dictionary for JSON serialization."""
|
||||||
|
return {
|
||||||
|
"repository": self.repository_path,
|
||||||
|
"analyzed_at": self.analyzed_at.isoformat(),
|
||||||
|
"files_analyzed": self.files_analyzed,
|
||||||
|
"total_commits": self.total_commits,
|
||||||
|
"unique_authors": self.unique_authors,
|
||||||
|
"bus_factor_overall": self.overall_bus_factor,
|
||||||
|
"gini_coefficient": self.gini_coefficient,
|
||||||
|
"files": self.files,
|
||||||
|
"hotspots": self.hotspots,
|
||||||
|
"suggestions": self.suggestions,
|
||||||
|
"risk_summary": self.risk_summary,
|
||||||
|
"metadata": self.metadata
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user