Skip to content

Commit fbb643b

Browse files
authored
fix(changelog): do not change the tag date if tag already exists (#861)
* fix(changelog): do not change the tag date if it already exists * fix: fix logic * refactor: revert the assignment
1 parent c2db791 commit fbb643b

File tree

5 files changed

+80
-4
lines changed

5 files changed

+80
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[changelog]
2+
# template for the changelog footer
3+
header = """
4+
# Changelog\n
5+
All notable changes to this project will be documented in this file.\n
6+
"""
7+
# template for the changelog body
8+
# https://keats.github.io/tera/docs/#introduction
9+
body = """
10+
{% if version %}\
11+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
12+
{% else %}\
13+
## [unreleased]
14+
{% endif %}\
15+
{% for group, commits in commits | group_by(attribute="group") %}
16+
### {{ group | upper_first }}
17+
{% for commit in commits %}
18+
- {{ commit.message | upper_first }}\
19+
{% endfor %}
20+
{% endfor %}\n
21+
"""
22+
# template for the changelog footer
23+
footer = """
24+
<!-- generated by git-cliff -->
25+
"""
26+
# remove the leading and trailing whitespace from the templates
27+
trim = true
28+
29+
[git]
30+
# regex for parsing and grouping commits
31+
commit_parsers = [
32+
{ message = "^feat", group = "Features", default_scope = "app" },
33+
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
34+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
5+
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
6+
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
7+
git tag v0.1.0
8+
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "feat(gui): add feature 2"
9+
GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit --allow-empty -m "fix(gui): fix feature 2"
10+
git tag v0.2.0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [0.2.0] - 2022-04-06
6+
7+
### Bug Fixes
8+
9+
- Fix feature 2
10+
11+
### Features
12+
13+
- Add feature 2
14+
15+
## [0.1.0] - 2022-04-06
16+
17+
### Bug Fixes
18+
19+
- Fix feature 1
20+
21+
### Features
22+
23+
- Add feature 1
24+
25+
<!-- generated by git-cliff -->

.github/workflows/test-fixtures.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ jobs:
9393
command: --bump --unreleased --with-tag-message "Some text"
9494
- fixtures-name: test-from-context
9595
command: --from-context context.json
96+
- fixtures-name: test-unchanged-tag-date
97+
command: --tag v0.2.0
9698

9799
steps:
98100
- name: Checkout

git-cliff/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,13 @@ fn process_repository<'a>(
235235
}
236236

237237
// Update tags.
238+
let mut tag_timestamp = None;
238239
if let Some(ref tag) = args.tag {
239240
if let Some(commit_id) = commits.first().map(|c| c.id().to_string()) {
240241
match tags.get(&commit_id) {
241242
Some(tag) => {
242243
warn!("There is already a tag ({}) for {}", tag.name, commit_id);
244+
tag_timestamp = Some(commits[0].time().seconds());
243245
}
244246
None => {
245247
tags.insert(commit_id, repository.resolve_tag(tag));
@@ -263,10 +265,13 @@ fn process_repository<'a>(
263265
release.message = tag.message.clone();
264266
release.commit_id = Some(commit_id);
265267
release.timestamp = if args.tag.as_deref() == Some(tag.name.as_str()) {
266-
SystemTime::now()
267-
.duration_since(UNIX_EPOCH)?
268-
.as_secs()
269-
.try_into()?
268+
match tag_timestamp {
269+
Some(timestamp) => timestamp,
270+
None => SystemTime::now()
271+
.duration_since(UNIX_EPOCH)?
272+
.as_secs()
273+
.try_into()?,
274+
}
270275
} else {
271276
git_commit.time().seconds()
272277
};

0 commit comments

Comments
 (0)