Skip to content

Commit 506c2d4

Browse files
authored
1 parent cf17868 commit 506c2d4

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

.generator/cli.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -757,22 +757,25 @@ def _process_changelog(
757757
)
758758

759759
# Group changes by type (e.g., feat, fix, docs)
760-
library_changes.sort(key=lambda x: x["type"])
761-
grouped_changes = itertools.groupby(library_changes, key=lambda x: x["type"])
762-
763-
for change_type, changes in grouped_changes:
760+
type_key = "type"
761+
source_commit_hash_key = "source_commit_hash"
762+
subject_key = "subject"
763+
library_changes.sort(key=lambda x: x[type_key])
764+
grouped_changes = itertools.groupby(library_changes, key=lambda x: x[type_key])
765+
766+
change_type_map = {
767+
"feat": "Features",
768+
"fix": "Bug Fixes",
769+
"docs": "Documentation",
770+
}
771+
for library_change_type, library_changes in grouped_changes:
764772
# We only care about feat, fix, docs
765-
adjusted_change_type = change_type.replace("!", "")
766-
change_type_map = {
767-
"feat": "Features",
768-
"fix": "Bug Fixes",
769-
"docs": "Documentation",
770-
}
771-
if adjusted_change_type in ["feat", "fix", "docs"]:
773+
adjusted_change_type = library_change_type.replace("!", "")
774+
if adjusted_change_type in change_type_map:
772775
entry_parts.append(f"\n\n### {change_type_map[adjusted_change_type]}\n")
773-
for change in changes:
774-
commit_link = f"([{change['source_commit_hash']}]({_REPO_URL}/commit/{change['source_commit_hash']}))"
775-
entry_parts.append(f"* {change['subject']} {commit_link}")
776+
for change in library_changes:
777+
commit_link = f"([{change[source_commit_hash_key]}]({_REPO_URL}/commit/{change[source_commit_hash_key]}))"
778+
entry_parts.append(f"* {change[subject_key]} {commit_link}")
776779

777780
new_entry_text = "\n".join(entry_parts)
778781
anchor_pattern = re.compile(
@@ -811,16 +814,17 @@ def _update_changelog_for_library(
811814
be updated.
812815
"""
813816

814-
source_path = f"{repo}/packages/{library_id}/CHANGELOG.md"
815-
output_path = f"{output}/packages/{library_id}/CHANGELOG.md"
817+
relative_path = f"packages/{library_id}/CHANGELOG.md"
818+
changelog_src = f"{repo}/{relative_path}"
819+
changelog_dest = f"{output}/{relative_path}"
816820
updated_content = _process_changelog(
817-
_read_text_file(source_path),
821+
_read_text_file(changelog_src),
818822
library_changes,
819823
version,
820824
previous_version,
821825
library_id,
822826
)
823-
_write_text_file(output_path, updated_content)
827+
_write_text_file(changelog_dest, updated_content)
824828

825829

826830
def handle_release_init(

0 commit comments

Comments
 (0)