MCPcopy Create free account
hub / github.com/commitizen-tools/commitizen / _get_config_data

Method _get_config_data

commitizen/commands/init.py:325–354  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

323 return update_changelog_on_bump
324
325 def _get_config_data(self) -> dict[str, Any]:
326 CZ_HOOK_CONFIG = {
327 "repo": "https://github.com/commitizen-tools/commitizen",
328 "rev": f"v{__version__}",
329 "hooks": [
330 {"id": "commitizen"},
331 {"id": "commitizen-branch", "stages": ["pre-push"]},
332 ],
333 }
334
335 pre_commit_config_path = Path(self._PRE_COMMIT_CONFIG_PATH)
336 if not pre_commit_config_path.is_file():
337 return {"repos": [CZ_HOOK_CONFIG]}
338
339 with pre_commit_config_path.open(
340 encoding=self.config.settings["encoding"]
341 ) as config_file:
342 config_data: dict[str, Any] = yaml.safe_load(config_file) or {}
343
344 if not isinstance(repos := config_data.get("repos"), list):
345 # .pre-commit-config.yaml exists but there's no "repos" key
346 config_data["repos"] = [CZ_HOOK_CONFIG]
347 return config_data
348
349 # Check if commitizen pre-commit hook is already in the config
350 if any("commitizen" in hook_config["repo"] for hook_config in repos):
351 out.write("commitizen already in pre-commit config")
352 else:
353 repos.append(CZ_HOOK_CONFIG)
354 return config_data
355
356
357def _write_config_to_file(

Callers 1

__call__Method · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected