-
Notifications
You must be signed in to change notification settings - Fork 438
Expand file tree
/
Copy pathmonorepo_commits.py
More file actions
79 lines (65 loc) · 2.76 KB
/
monorepo_commits.py
File metadata and controls
79 lines (65 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright 2025 © BeeAI a Series of LF Projects, LLC
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any
from commitizen.cz.conventional_commits import ConventionalCommitsCz # type: ignore
__all__ = ["MonorepoCommitsCz"]
if TYPE_CHECKING:
from commitizen import git
from commitizen.question import CzQuestion
class MonorepoCommitsCz(ConventionalCommitsCz):
change_type_map = { # noqa: RUF012
"feat": "Features",
"fix": "Bug Fixes",
"refactor": "Refactor",
"perf": "Performance Improvements",
}
# pyrefly: ignore [bad-override]
def changelog_message_builder_hook(
self, parsed_message: dict[str, Any], commit: git.GitCommit
) -> dict[str, Any] | Iterable[dict[str, Any]] | None:
from commitizen import git
changed_files = git.get_filenames_in_commit(commit.rev) or []
has_python_changes = any(file.startswith("python/") for file in changed_files)
if not has_python_changes:
return None
parent_hook = super().changelog_message_builder_hook
return parent_hook(parsed_message, commit) if parent_hook else parsed_message
def questions(self) -> list[CzQuestion]:
questions = super().questions()
for index, question in enumerate(questions):
if question["type"] == "list" and question["name"] == "prefix":
question["choices"].append({"value": "chore", "name": "chore: other uncategorized changes"})
if question["name"] == "scope":
questions[index] = { # type: ignore
"type": "list",
"name": "scope",
"message": "What is the scope of this change?",
"filter": lambda value: value or "",
"choices": [
{"name": name or "", "value": name}
for name in [
None,
"adapters",
"agents",
"middlewares",
"backend",
"tools",
"cache",
"emitter",
"examples",
"internals",
"logger",
"memory",
"serializer",
"infra",
"deps",
"instrumentation",
"workflows",
"rag",
]
],
}
break
return questions