fix: auto-load YAML config on CLI startup

CLI now reads ~/.config/redmine-reporter/config.yml automatically.
Previously Config.load_yaml() existed but was never called.
This commit is contained in:
Кокос Артем Николаевич
2026-07-03 18:19:30 +07:00
parent b1a565bc9e
commit 0fa4e271a7
2 changed files with 19 additions and 1 deletions

View File

@@ -211,6 +211,10 @@ def main(argv: Optional[List[str]] = None) -> int:
Config.set_redmine_url(args.url) Config.set_redmine_url(args.url)
Config.set_redmine_api_key(args.api_key) Config.set_redmine_api_key(args.api_key)
# Автозагрузка YAML-конфига
yaml_path = args.config_path
Config.load_yaml(yaml_path)
# Настройка уровня логирования # Настройка уровня логирования
if args.debug: if args.debug:
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s") logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")

View File

@@ -62,7 +62,7 @@ def test_cli_returns_zero_on_no_entries(mock_fetch):
@mock.patch.dict(os.environ, {}, clear=True) @mock.patch.dict(os.environ, {}, clear=True)
def test_cli_config_error(): def test_cli_config_error():
"""Невалидный конфиг -- выход 1.""" """Невалидный конфиг -- выход 1."""
code = main(["--date", "2026-01-01--2026-01-31"]) code = main(["--date", "2026-01-01--2026-01-31", "--config-path", "/nonexistent/config.yml"])
assert code == 1 assert code == 1
@@ -393,3 +393,17 @@ class TestInitConfig:
assert "redmine" in data assert "redmine" in data
assert data["redmine"]["url"] == "" assert data["redmine"]["url"] == ""
assert data["redmine"]["api_key"] == "" assert data["redmine"]["api_key"] == ""
@mock.patch.dict(os.environ, {}, clear=True)
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
def test_cli_autoloads_yaml_config(mock_fetch, tmp_path):
"""CLI автоматически подгружает YAML-конфиг при запуске."""
config_path = tmp_path / "config.yml"
config_path.write_text(
"redmine:\n url: https://yaml-redmine.example.com/\n api_key: yaml-token\n"
)
mock_fetch.return_value = None
code = main(["--date", "2026-01-01--2026-01-31", "--config-path", str(config_path)])
assert code == 0