fix: add models and utils modules
This commit is contained in:
@@ -1,35 +1,21 @@
|
|||||||
import os
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def load_config(config_path: Optional[str] = None) -> Dict[str, Any]:
|
def load_config(config_path: Optional[str] = None) -> Dict[str, Any]:
|
||||||
"""Load configuration from file or use defaults."""
|
"""Load configuration from a YAML file."""
|
||||||
if config_path and os.path.exists(config_path):
|
if config_path is None:
|
||||||
with open(config_path, "r") as f:
|
config_path = Path(".git-insights/config.yaml")
|
||||||
|
|
||||||
|
config_file = Path(config_path)
|
||||||
|
|
||||||
|
if not config_file.exists():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(config_file, "r") as f:
|
||||||
return yaml.safe_load(f) or {}
|
return yaml.safe_load(f) or {}
|
||||||
|
except Exception:
|
||||||
default_paths = [
|
return {}
|
||||||
".git-insights/config.yaml",
|
|
||||||
os.path.expanduser("~/.git-insights/config.yaml"),
|
|
||||||
]
|
|
||||||
|
|
||||||
for path in default_paths:
|
|
||||||
if os.path.exists(path):
|
|
||||||
with open(path, "r") as f:
|
|
||||||
return yaml.safe_load(f) or {}
|
|
||||||
|
|
||||||
return get_default_config()
|
|
||||||
|
|
||||||
|
|
||||||
def get_default_config() -> Dict[str, Any]:
|
|
||||||
"""Return default configuration."""
|
|
||||||
return {
|
|
||||||
"repository_path": ".",
|
|
||||||
"analysis_days": 30,
|
|
||||||
"output_format": "json",
|
|
||||||
"churn_threshold": 500,
|
|
||||||
"risky_commit_threshold": 500,
|
|
||||||
"merge_commit_flag": True,
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user