(self)
| 85 | self.cz = factory.committer_factory(self.config) |
| 86 | |
| 87 | def __call__(self) -> None: |
| 88 | if self.config.path: |
| 89 | out.line(f"Config file {self.config.path} already exists") |
| 90 | return |
| 91 | |
| 92 | out.info("Welcome to commitizen!\n") |
| 93 | out.line( |
| 94 | "Answer the following questions to configure your project.\n" |
| 95 | "For further configuration, visit:\n" |
| 96 | "\n" |
| 97 | "https://commitizen-tools.github.io/commitizen/config/" |
| 98 | "\n" |
| 99 | ) |
| 100 | |
| 101 | # Collect information |
| 102 | try: |
| 103 | config_path = self._ask_config_path() # select |
| 104 | cz_name = self._ask_name() # select |
| 105 | version_provider = self._ask_version_provider() # select |
| 106 | tag = self._ask_tag() # confirm & select |
| 107 | version_scheme = self._ask_version_scheme() # select |
| 108 | version = get_version_scheme(self.config.settings, version_scheme)(tag) |
| 109 | tag_format = self._ask_tag_format(tag) # confirm & text |
| 110 | update_changelog_on_bump = self._ask_update_changelog_on_bump() # confirm |
| 111 | major_version_zero = self._ask_major_version_zero(version) # confirm |
| 112 | hook_types: list[str] | None = questionary.checkbox( |
| 113 | "What types of pre-commit hook you want to install? (Leave blank if you don't want to install)", |
| 114 | choices=[ |
| 115 | questionary.Choice("commit-msg", checked=False), |
| 116 | questionary.Choice("pre-push", checked=False), |
| 117 | ], |
| 118 | ).unsafe_ask() |
| 119 | except KeyboardInterrupt: |
| 120 | raise InitFailedError("Stopped by user") |
| 121 | |
| 122 | if hook_types: |
| 123 | config_data = self._get_config_data() |
| 124 | with smart_open( |
| 125 | self._PRE_COMMIT_CONFIG_PATH, |
| 126 | "w", |
| 127 | encoding=self.config.settings["encoding"], |
| 128 | ) as config_file: |
| 129 | yaml.safe_dump(config_data, stream=config_file) |
| 130 | |
| 131 | if not project_info.is_pre_commit_installed(): |
| 132 | raise InitFailedError( |
| 133 | "Failed to install pre-commit hook.\n" |
| 134 | "pre-commit is not installed in current environment." |
| 135 | ) |
| 136 | |
| 137 | cmd_args = ["pre-commit", "install"] |
| 138 | for ty in hook_types: |
| 139 | cmd_args.extend(["--hook-type", ty]) |
| 140 | c = cmd.run(cmd_args) |
| 141 | if c.return_code != 0: |
| 142 | cmd_str = " ".join(cmd_args) |
| 143 | raise InitFailedError( |
| 144 | "Failed to install pre-commit hook.\n" |
nothing calls this directly
no test coverage detected