Skip to content

Commit

Permalink
DEV: Fix changelog generator regarding whitespace and handling of "Ot…
Browse files Browse the repository at this point in the history
…her" group (#2492)
  • Loading branch information
stefan6419846 committed Mar 29, 2024
1 parent 68b0465 commit 253cde4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
7 changes: 5 additions & 2 deletions make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:

if grouped:
output += "\n### Other\n"
output_with_user += "\n### Other\n"
for prefix in grouped:
output += f"- {prefix}: {grouped[prefix]}\n"
for commit in grouped[prefix]:
output += f"- {prefix}: {commit['msg']}\n"
output_with_user += f"- {prefix}: {commit['msg']} by @{commit['author']}\n"

return output, output_with_user

Expand Down Expand Up @@ -341,7 +344,7 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:
raise ValueError(f"Invalid commit line: '{line}'")
commit_hash, rest, author = parts
if ":" in rest:
prefix, message = rest.split(":", 1)
prefix, message = rest.split(": ", 1)
else:
prefix = ""
message = rest
Expand Down
82 changes: 67 additions & 15 deletions tests/scripts/test_make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ def test_get_git_commits_since_tag():
make_release.Change(
commit_hash="b7bfd0d7eddfd0865a94cc9e7027df6596242cf7",
prefix="BUG",
message=" Use NumberObject for /Border elements of annotations (#2451)",
message="Use NumberObject for /Border elements of annotations (#2451)",
author="rsinger417",
author_login="rsinger417",
),
make_release.Change(
commit_hash="8cacb0fc8fee9920b0515d1289e6ee8191eb3f21",
prefix="DOC",
message=" Document easier way to update metadata (#2454)",
message="Document easier way to update metadata (#2454)",
author="Stefan",
author_login="stefan6419846",
),
make_release.Change(
commit_hash="3fb63f7e3839ce39ac98978c996f3086ba230a20",
prefix="TST",
message=" Avoid catching not emitted warnings (#2429)",
message="Avoid catching not emitted warnings (#2429)",
author="Stefan",
author_login="stefan6419846",
),
make_release.Change(
commit_hash="61b73d49778e8f0fb172d5323e67677c9974e420",
prefix="DOC",
message=" Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426)",
message="Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426)",
author="CWKSC",
author_login="CWKSC",
),
make_release.Change(
commit_hash="f851a532a5ec23b572d86bd7185b327a3fac6b58",
prefix="DEV",
message=" Bump codecov/codecov-action from 3 to 4 (#2430)",
message="Bump codecov/codecov-action from 3 to 4 (#2430)",
author="dependabot[bot]",
author_login="dependabot[bot]",
),
Expand All @@ -75,33 +75,85 @@ def test_get_formatted_changes():
output
== """
### Bug Fixes (BUG)
- Use NumberObject for /Border elements of annotations (#2451)
- Use NumberObject for /Border elements of annotations (#2451)
### Documentation (DOC)
- Document easier way to update metadata (#2454)
- Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426)
- Document easier way to update metadata (#2454)
- Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426)
### Developer Experience (DEV)
- Bump codecov/codecov-action from 3 to 4 (#2430)
- Bump codecov/codecov-action from 3 to 4 (#2430)
### Testing (TST)
- Avoid catching not emitted warnings (#2429)
- Avoid catching not emitted warnings (#2429)
"""
)
assert (
output_with_user
== """
### Bug Fixes (BUG)
- Use NumberObject for /Border elements of annotations (#2451) by @rsinger417
- Use NumberObject for /Border elements of annotations (#2451) by @rsinger417
### Documentation (DOC)
- Document easier way to update metadata (#2454) by @stefan6419846
- Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426) by @CWKSC
- Document easier way to update metadata (#2454) by @stefan6419846
- Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426) by @CWKSC
### Developer Experience (DEV)
- Bump codecov/codecov-action from 3 to 4 (#2430) by @dependabot[bot]
- Bump codecov/codecov-action from 3 to 4 (#2430) by @dependabot[bot]
### Testing (TST)
- Avoid catching not emitted warnings (#2429) by @stefan6419846
- Avoid catching not emitted warnings (#2429) by @stefan6419846
"""
)


def test_get_formatted_changes__other():
make_release = pytest.importorskip("make_release")

changes = [
make_release.Change(
commit_hash="f20c36eabd59ea661f30c5da35af7c9e435c7de9",
prefix="",
message="Improve lossless compression example (#2488)",
author="j-t-1",
author_login="j-t-1"
),
make_release.Change(
commit_hash="afbee382f8fd2b39588db6470b9b2b2c82905318",
prefix="ENH",
message="Add reattach_fields function (#2480)",
author="pubpub-zz",
author_login="pubpub-zz"
),
make_release.Change(
commit_hash="cd705f959064d8125397ddf4f7bdd2ea296f889f",
prefix="FIX",
message="Broken test due to expired test file URL (#2468)",
author="pubpub-zz",
author_login="pubpub-zz"
),
]
with mock.patch.object(make_release, "get_git_commits_since_tag", return_value=changes):
output, output_with_user = make_release.get_formatted_changes("dummy")

assert (
output == """
### New Features (ENH)
- Add reattach_fields function (#2480)
### Other
- : Improve lossless compression example (#2488)
- FIX: Broken test due to expired test file URL (#2468)
"""
)

assert (
output_with_user == """
### New Features (ENH)
- Add reattach_fields function (#2480) by @pubpub-zz
### Other
- : Improve lossless compression example (#2488) by @j-t-1
- FIX: Broken test due to expired test file URL (#2468) by @pubpub-zz
"""
)

0 comments on commit 253cde4

Please sign in to comment.