Skip to content

Commit c4b3dff

Browse files
committed
🩹 fix(changelog): prepend new changelog entries if file exists
1 parent 6653c9b commit c4b3dff

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## v0.14.0
2+
3+
[v0.13.2...v0.14.0](https://github.com/Jannchie/tgit/compare/v0.13.2...v0.14.0)
4+
5+
### :sparkles: Features
6+
7+
- **changelog**: add incremental changelog generation && support appending to existing file - By [Jianqi Pan](mailto:[email protected]) in [2d193a5](https://github.com/Jannchie/tgit/commit/2d193a5)
8+
9+
### :adhesive_bandage: Fixes
10+
11+
- **changelog**: remove head from default changelog range && update changelog entries - By [Jianqi Pan](mailto:[email protected]) in [f6509e3](https://github.com/Jannchie/tgit/commit/f6509e3)
12+
113
## v0.13.2
214

315
[v0.13.1...v0.13.2](https://github.com/Jannchie/tgit/compare/v0.13.1...v0.13.2)

tgit/changelog.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,15 @@ def handle_changelog(args: ChangelogArgs) -> None:
288288
changelogs += changelog
289289
progress.update(task, advance=1)
290290
if changelogs:
291-
mode = "a" if latest_tag_in_file else "w"
292-
with Path(args.output).open(mode, encoding="utf-8") as output_file:
293-
output_file.write(changelogs.strip("\n") + "\n")
291+
if latest_tag_in_file:
292+
# prepend: 新内容写在最前面
293+
with Path(args.output).open("r", encoding="utf-8") as f:
294+
old_content = f.read()
295+
with Path(args.output).open("w", encoding="utf-8") as f:
296+
f.write(changelogs.strip("\n") + "\n\n" + old_content)
297+
else:
298+
with Path(args.output).open("w", encoding="utf-8") as output_file:
299+
output_file.write(changelogs.strip("\n") + "\n")
294300
print()
295301
print(changelogs.strip("\n"))
296302
return

0 commit comments

Comments
 (0)