| 78 | |
| 79 | |
| 80 | class Init: |
| 81 | _PRE_COMMIT_CONFIG_PATH = ".pre-commit-config.yaml" |
| 82 | |
| 83 | def __init__(self, config: BaseConfig, *args: object) -> None: |
| 84 | self.config: BaseConfig = config |
| 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 = self._ask_hook_types() |
| 113 | except KeyboardInterrupt: |
| 114 | raise InitFailedError("Stopped by user") |
| 115 | |
| 116 | if hook_types: |
| 117 | config_data = self._get_config_data() |
| 118 | with smart_open( |
| 119 | self._PRE_COMMIT_CONFIG_PATH, |
| 120 | "w", |
| 121 | encoding=self.config.settings["encoding"], |
| 122 | ) as config_file: |
| 123 | yaml.safe_dump(config_data, stream=config_file) |
| 124 | |
| 125 | installer = self._ask_hook_installer() |
| 126 | |
| 127 | cmd_args = [installer, "install"] |
| 128 | for ty in hook_types: |
| 129 | cmd_args.extend(["--hook-type", ty]) |
| 130 | c = cmd.run(cmd_args) |
| 131 | if c.return_code != 0: |
| 132 | cmd_str = " ".join(cmd_args) |
| 133 | raise InitFailedError( |
| 134 | "Failed to install pre-commit hook.\n" |
| 135 | f"Error running {cmd_str}." |
| 136 | "Outputs are attached below:\n" |
| 137 | f"stdout: {c.out}\n" |
nothing calls this directly
no outgoing calls
no test coverage detected