From 72d45f58847e6df5740b011309256290ff3a07f8 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 17:54:27 +0000 Subject: [PATCH] Initial upload with CI/CD workflow --- app/src/git_commit_generator/config.py | 109 +++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/src/git_commit_generator/config.py diff --git a/app/src/git_commit_generator/config.py b/app/src/git_commit_generator/config.py new file mode 100644 index 0000000..ad95426 --- /dev/null +++ b/app/src/git_commit_generator/config.py @@ -0,0 +1,109 @@ +"""Configuration management for git-commit-message-generator.""" +import os +from pathlib import Path +from typing import Optional + +import yaml + + +class Config: + """Configuration management class.""" + + def __init__(self, config_path: Optional[str] = None): + """Initialize configuration. + + Args: + config_path: Path to config file. Defaults to None. + """ + self.config_path = config_path or os.environ.get( + "GIT_COMMIT_GENERATOR_CONFIG" + ) + self._config = self._load_config() + + def _load_config(self) -> dict: + """Load configuration from file. + + Returns: + Dictionary containing configuration. + """ + config = { + "ollama_host": os.environ.get("OLLAMA_HOST", "http://localhost:11434"), + "ollama_model": os.environ.get("OLLAMA_MODEL", "llama3"), + "prompt_dir": os.environ.get( + "PROMPT_DIR", str(Path(__file__).parent.parent / "prompts") + ), + } + + if self.config_path: + config_file = Path(self.config_path) + if config_file.exists(): + with open(config_file, "r") as f: + file_config = yaml.safe_load(f) or {} + config.update(file_config) + + return config + + @property + def ollama_host(self) -> str: + """Get Ollama host URL. + + Returns: + Ollama host URL. + """ + return self._config["ollama_host"] + + @property + def ollama_model(self) -> str: + """Get default Ollama model. + + Returns: + Ollama model name. + """ + return self._config["ollama_model"] + + @property + def prompt_dir(self) -> str: + """Get prompt directory path. + + Returns: + Path to prompt templates directory. + """ + return self._config["prompt_dir"] + + def get_prompt_path(self, prompt_name: str) -> Path: + """Get full path to a prompt file. + + Args: + prompt_name: Name of the prompt file. + + Returns: + Full path to the prompt file. + """ + return Path(self.prompt_dir) / prompt_name + + def read_prompt(self, prompt_name: str) -> str: + """Read a prompt template file. + + Args: + prompt_name: Name of the prompt file. + + Returns: + Content of the prompt file. + """ + prompt_path = self.get_prompt_path(prompt_name) + if prompt_path.exists(): + with open(prompt_path, "r") as f: + return f.read() + return "" + + +def get_config(config_path: Optional[str] = None) -> Config: + """Get configuration instance. + + Args: + config_path: Optional path to config file. + + Returns: + Config instance. + """ + return Config(config_path)