Skip to content

Commit

Permalink
feat(changelog)!: use current time for --tag argument (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Dec 19, 2022
1 parent 29b3dd1 commit e2cd07b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions git-cliff-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pub enum Error {
/// Errors that may occur during parsing or compiling a regular expression.
#[error("Cannot parse/compile regex: `{0}`")]
RegexError(#[from] regex::Error),
/// Error that may occur due to system time related anomalies.
#[error("System time error: `{0}`")]
SystemTimeError(#[from] std::time::SystemTimeError),
/// Error that may occur while parsing integers.
#[error("Failed to parse integer: `{0}`")]
IntParseError(#[from] std::num::TryFromIntError),
}

/// Result type of the core library.
Expand Down
17 changes: 14 additions & 3 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ use std::fs::{
File,
};
use std::io;
use std::time::{
SystemTime,
UNIX_EPOCH,
};

/// Checks for a new version on crates.io
#[cfg(feature = "update-informer")]
Expand Down Expand Up @@ -232,14 +236,14 @@ pub fn run(mut args: Opt) -> Result<()> {
}

// Update tags.
if let Some(tag) = args.tag {
if let Some(ref tag) = args.tag {
if let Some(commit_id) = commits.first().map(|c| c.id().to_string()) {
match tags.get(&commit_id) {
Some(tag) => {
warn!("There is already a tag ({}) for {}", tag, commit_id)
}
None => {
tags.insert(commit_id, tag);
tags.insert(commit_id, tag.to_string());
}
}
}
Expand All @@ -260,7 +264,14 @@ pub fn run(mut args: Opt) -> Result<()> {
if let Some(tag) = tags.get(&commit_id) {
releases[release_index].version = Some(tag.to_string());
releases[release_index].commit_id = Some(commit_id);
releases[release_index].timestamp = git_commit.time().seconds();
releases[release_index].timestamp = if args.tag.as_deref() == Some(tag) {
SystemTime::now()
.duration_since(UNIX_EPOCH)?
.as_secs()
.try_into()?
} else {
git_commit.time().seconds()
};
previous_release.previous = None;
releases[release_index].previous = Some(Box::new(previous_release));
previous_release = releases[release_index].clone();
Expand Down

0 comments on commit e2cd07b

Please sign in to comment.