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

Function generate_tree_from_commits

commitizen/changelog.py:92–171  ·  view source on GitHub ↗
(
    commits: list[GitCommit],
    tags: list[GitTag],
    commit_parser: str,
    changelog_pattern: str,
    unreleased_version: str | None = None,
    change_type_map: dict[str, str] | None = None,
    changelog_message_builder_hook: MessageBuilderHook | None = None,
    changelog_release_hook: ChangelogReleaseHook | None = None,
    rules: TagRules | None = None,
    during_version_bump: bool = False,
)

Source from the content-addressed store, hash-verified

90
91
92def generate_tree_from_commits(
93 commits: list[GitCommit],
94 tags: list[GitTag],
95 commit_parser: str,
96 changelog_pattern: str,
97 unreleased_version: str | None = None,
98 change_type_map: dict[str, str] | None = None,
99 changelog_message_builder_hook: MessageBuilderHook | None = None,
100 changelog_release_hook: ChangelogReleaseHook | None = None,
101 rules: TagRules | None = None,
102 during_version_bump: bool = False,
103) -> Generator[dict[str, Any], None, None]:
104 pat = re.compile(changelog_pattern)
105 map_pat = re.compile(commit_parser, re.MULTILINE)
106 body_map_pat = re.compile(commit_parser, re.MULTILINE | re.DOTALL)
107 rules = rules or TagRules()
108
109 # Check if the latest commit is not tagged
110 if during_version_bump and rules.merge_prereleases:
111 current_tag = None
112 else:
113 current_tag = get_commit_tag(commits[0], tags) if commits else None
114 current_tag_name = unreleased_version or "Unreleased"
115 current_tag_date = (
116 date.today().isoformat() if unreleased_version is not None else ""
117 )
118
119 used_tags: set[GitTag] = set()
120 if current_tag:
121 used_tags.add(current_tag)
122 if current_tag.name:
123 current_tag_name = current_tag.name
124 current_tag_date = current_tag.date
125
126 commit_tag: GitTag | None = None
127 changes: dict = defaultdict(list)
128 for commit in commits:
129 if (
130 (commit_tag := get_commit_tag(commit, tags))
131 and commit_tag not in used_tags
132 and rules.include_in_changelog(commit_tag)
133 ):
134 used_tags.add(commit_tag)
135 release = {
136 "version": current_tag_name,
137 "date": current_tag_date,
138 "changes": changes,
139 }
140 if changelog_release_hook:
141 release = changelog_release_hook(release, commit_tag)
142 yield release
143 current_tag_name = commit_tag.name
144 current_tag_date = commit_tag.date
145 changes = defaultdict(list)
146
147 if not pat.match(commit.message):
148 continue
149

Callers

nothing calls this directly

Calls 5

TagRulesClass · 0.90
get_commit_tagFunction · 0.85
process_commit_messageFunction · 0.85
include_in_changelogMethod · 0.80
changelog_release_hookFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…