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

Method __call__

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

Source from the content-addressed store, hash-verified

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"
138 f"stderr: {c.err}"
139 )
140 out.write("commitizen pre-commit hook is now installed in your '.git'\n")
141
142 _write_config_to_file(
143 path=config_path,
144 cz_name=cz_name,

Callers

nothing calls this directly

Calls 15

_ask_config_pathMethod · 0.95
_ask_nameMethod · 0.95
_ask_version_providerMethod · 0.95
_ask_tagMethod · 0.95
_ask_version_schemeMethod · 0.95
_ask_tag_formatMethod · 0.95
_ask_hook_typesMethod · 0.95
_get_config_dataMethod · 0.95
_ask_hook_installerMethod · 0.95
get_version_schemeFunction · 0.90

Tested by

no test coverage detected