MCPcopy Index your code
hub / github.com/commitizen-tools/commitizen / _get_config_data

Method _get_config_data

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

Source from the content-addressed store, hash-verified

291 return update_changelog_on_bump
292
293 def _get_config_data(self) -> dict[str, Any]:
294 CZ_HOOK_CONFIG = {
295 "repo": "https://github.com/commitizen-tools/commitizen",
296 "rev": f"v{__version__}",
297 "hooks": [
298 {"id": "commitizen"},
299 {"id": "commitizen-branch", "stages": ["pre-push"]},
300 ],
301 }
302
303 pre_commit_config_path = Path(self._PRE_COMMIT_CONFIG_PATH)
304 if not pre_commit_config_path.is_file():
305 return {"repos": [CZ_HOOK_CONFIG]}
306
307 with pre_commit_config_path.open(
308 encoding=self.config.settings["encoding"]
309 ) as config_file:
310 config_data: dict[str, Any] = yaml.safe_load(config_file) or {}
311
312 if not isinstance(repos := config_data.get("repos"), list):
313 # .pre-commit-config.yaml exists but there's no "repos" key
314 config_data["repos"] = [CZ_HOOK_CONFIG]
315 return config_data
316
317 # Check if commitizen pre-commit hook is already in the config
318 if any("commitizen" in hook_config["repo"] for hook_config in repos):
319 out.write("commitizen already in pre-commit config")
320 else:
321 repos.append(CZ_HOOK_CONFIG)
322 return config_data
323
324
325def _write_config_to_file(

Callers 1

__call__Method · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected