| 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 | |
| 325 | def _write_config_to_file( |