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

Method _get_next_git_version

commitizen/commands/version.py:159–204  ·  view source on GitHub ↗

Calculate the next version based on commits.

(
        self, current_version: VersionProtocol
    )

Source from the content-addressed store, hash-verified

157 out.write(__version__)
158
159 def _get_next_git_version(
160 self, current_version: VersionProtocol
161 ) -> VersionProtocol:
162 """Calculate the next version based on commits."""
163 rules = TagRules.from_settings(self.config.settings)
164 current_tag = rules.find_tag_for(git.get_tags(), current_version)
165 commits = git.get_commits(current_tag.name if current_tag else None)
166
167 # No commits, there is no need to create an empty tag.
168 # Unless we previously had a prerelease.
169 if not commits and not current_version.is_prerelease:
170 raise NoCommitsFoundError("[NO_COMMITS_FOUND]\nNo new commits found.")
171
172 bump_map = (
173 self.cz.bump_map_major_version_zero
174 if self.config.settings["major_version_zero"]
175 else self.cz.bump_map
176 )
177 bump_pattern = self.cz.bump_pattern
178
179 if not bump_map or not bump_pattern:
180 raise NoPatternMapError(
181 f"'{self.config.settings['name']}' rule does not support bump"
182 )
183 next_increment = VersionIncrement.get_highest_by_messages(
184 (commit.message for commit in self.cz.filter_commits_before_bump(commits)),
185 bump_pattern,
186 bump_map,
187 )
188 increment: Increment | None
189 if next_increment == VersionIncrement.NONE:
190 increment = None
191 elif next_increment == VersionIncrement.PATCH:
192 increment = "PATCH"
193 elif next_increment == VersionIncrement.MINOR:
194 increment = "MINOR"
195 else:
196 increment = "MAJOR"
197
198 # TODO: Consider adding all the parameters `.bump` supports:
199 # prerelease, prerelease_offset,exact_increment, etc..
200 new_version = current_version.bump(
201 increment,
202 )
203
204 return new_version

Callers 1

__call__Method · 0.95

Calls 7

NoCommitsFoundErrorClass · 0.90
NoPatternMapErrorClass · 0.90
from_settingsMethod · 0.80
find_tag_forMethod · 0.80
bumpMethod · 0.45

Tested by

no test coverage detected