MCPcopy Index your code
hub / github.com/commitizen-tools/commitizen / __call__

Method __call__

commitizen/commands/check.py:87–118  ·  view source on GitHub ↗

Validate if commit messages follows the conventional pattern. Raises: InvalidCommitMessageError: if the commit provided does not follow the conventional pattern NoCommitsFoundError: if no commit is found with the given range

(self)

Source from the content-addressed store, hash-verified

85 self.cz = factory.committer_factory(self.config)
86
87 def __call__(self) -> None:
88 """Validate if commit messages follows the conventional pattern.
89
90 Raises:
91 InvalidCommitMessageError: if the commit provided does not follow the conventional pattern
92 NoCommitsFoundError: if no commit is found with the given range
93 """
94 commits = self._get_commits()
95 if not commits:
96 raise NoCommitsFoundError(f"No commit found with range: '{self.rev_range}'")
97
98 pattern = re.compile(self.cz.schema_pattern())
99 invalid_commits = [
100 (commit, check.errors)
101 for commit in commits
102 if not (
103 check := self.cz.validate_commit_message(
104 commit_msg=commit.message,
105 pattern=pattern,
106 allow_abort=self.allow_abort,
107 allowed_prefixes=self.allowed_prefixes,
108 max_msg_length=self.max_msg_length,
109 commit_hash=commit.rev,
110 )
111 ).is_valid
112 ]
113
114 if invalid_commits:
115 raise InvalidCommitMessageError(
116 self.cz.format_exception_message(invalid_commits)
117 )
118 out.success("Commit validation: successful!")
119
120 def _get_commit_message(self) -> str | None:
121 if self.commit_msg_file is None:

Callers

nothing calls this directly

Calls 6

_get_commitsMethod · 0.95
NoCommitsFoundErrorClass · 0.90
schema_patternMethod · 0.45

Tested by

no test coverage detected