From 848e487b759ec8b1f5bde4e1a53963e4fc755d7d Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 29 Jan 2026 12:00:29 +0000 Subject: [PATCH] Initial upload of auto-changelog-generator --- src/changeloggen/config.py | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/changeloggen/config.py diff --git a/src/changeloggen/config.py b/src/changeloggen/config.py new file mode 100644 index 0000000..ac18576 --- /dev/null +++ b/src/changeloggen/config.py @@ -0,0 +1,92 @@ +from pathlib import Path +from typing import Optional +import os +import yaml + + +class Config: + """Configuration for changeloggen.""" + + def __init__( + self, + ollama_url: str = "http://localhost:11434", + model: str = "llama3.2", + temperature: float = 0.3, + output_format: str = "markdown", + include_unstaged: bool = False, + custom_prompts: Optional[dict] = None + ): + self.ollama_url = ollama_url + self.model = model + self.temperature = temperature + self.output_format = output_format + self.include_unstaged = include_unstaged + self.custom_prompts = custom_prompts or {} + + +def find_config_file() -> Optional[Path]: + """Find configuration file in standard locations.""" + search_paths = [ + Path(".changeloggen.yaml"), + Path(".changeloggen.yml"), + Path(os.path.expanduser("~/.config/changeloggen/config.yaml")), + ] + + for path in search_paths: + if path.exists(): + return path + + return None + + +def load_config(config_path: Optional[Path] = None) -> Config: + """Load configuration from file or environment variables.""" + if config_path is None: + config_path = find_config_file() + + config = Config() + + if config_path and config_path.exists(): + try: + with open(config_path, 'r') as f: + data = yaml.safe_load(f) or {} + + if 'ollama_url' in data: + config.ollama_url = data['ollama_url'] + if 'model' in data: + config.model = data['model'] + if 'temperature' in data: + config.temperature = float(data['temperature']) + if 'output_format' in data: + config.output_format = data['output_format'] + if 'include_unstaged' in data: + config.include_unstaged = data['include_unstaged'] + if 'custom_prompts' in data: + config.custom_prompts = data['custom_prompts'] + except Exception: + pass + + config.ollama_url = os.environ.get("CHANGELOGGEN_OLLAMA_URL", config.ollama_url) + config.model = os.environ.get("CHANGELOGGEN_MODEL", config.model) + + if os.environ.get("CHANGELOGGEN_NO_COLOR"): + os.environ["NO_COLOR"] = os.environ.get("CHANGELOGGEN_NO_COLOR") + + return config + + +def save_config(config: Config, config_path: Path) -> None: + """Save configuration to file.""" + config_path.parent.mkdir(parents=True, exist_ok=True) + + data = { + 'ollama_url': config.ollama_url, + 'model': config.model, + 'temperature': config.temperature, + 'output_format': config.output_format, + 'include_unstaged': config.include_unstaged, + 'custom_prompts': config.custom_prompts + } + + with open(config_path, 'w') as f: + yaml.dump(data, f, default_flow_style=False)