mirror of
https://github.com/orhun/git-cliff.git
synced 2024-09-19 03:08:30 +03:00
feat(changelog): add release dates to the template
Signed-off-by: orhun <orhunparmaksiz@gmail.com>
This commit is contained in:
parent
1b26f1262e
commit
cb7493747b
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -1,5 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
@ -315,6 +317,7 @@ dependencies = [
|
||||
name = "gitolith-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"gitolith-core",
|
||||
"log",
|
||||
"pretty_env_logger",
|
||||
|
@ -16,6 +16,7 @@ edition = "2018"
|
||||
gitolith-core = { path = "../gitolith-core" }
|
||||
pretty_env_logger = "0.4.0"
|
||||
log = "0.4.14"
|
||||
chrono = "0.4.19"
|
||||
|
||||
[dependencies.structopt]
|
||||
version = "0.3"
|
||||
|
@ -1,6 +1,11 @@
|
||||
mod args;
|
||||
|
||||
use args::Opt;
|
||||
use chrono::{
|
||||
DateTime,
|
||||
NaiveDateTime,
|
||||
Utc,
|
||||
};
|
||||
use gitolith_core::changelog::Changelog;
|
||||
use gitolith_core::commit::Commit;
|
||||
use gitolith_core::config::Config;
|
||||
@ -39,12 +44,20 @@ fn main() -> Result<()> {
|
||||
};
|
||||
let mut release_index = 0;
|
||||
for git_commit in commits.into_iter().rev() {
|
||||
let commit = Commit::from(git_commit);
|
||||
let commit = Commit::from(&git_commit);
|
||||
let commit_id = commit.id.to_string();
|
||||
release_root.releases[release_index].commits.push(commit);
|
||||
if let Some(tag) = tags.get(&commit_id) {
|
||||
release_root.releases[release_index].version = Some(tag.to_string());
|
||||
release_root.releases[release_index].commit_id = Some(commit_id);
|
||||
release_root.releases[release_index].date = Some(
|
||||
DateTime::<Utc>::from_utc(
|
||||
NaiveDateTime::from_timestamp(git_commit.time().seconds(), 0),
|
||||
Utc,
|
||||
)
|
||||
.format(&config.changelog.date_format)
|
||||
.to_string(),
|
||||
);
|
||||
release_index += 1;
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ pub struct Commit<'a> {
|
||||
pub group: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a> From<GitCommit<'a>> for Commit<'a> {
|
||||
fn from(commit: GitCommit<'a>) -> Self {
|
||||
impl<'a> From<&GitCommit<'a>> for Commit<'a> {
|
||||
fn from(commit: &GitCommit<'a>) -> Self {
|
||||
Self::new(
|
||||
commit.id().to_string(),
|
||||
commit.message().unwrap_or_default().to_string(),
|
||||
|
@ -29,6 +29,7 @@ pub struct ChangelogConfig {
|
||||
pub group_parsers: Vec<GroupParser>,
|
||||
pub filter_group: bool,
|
||||
pub tag_pattern: String,
|
||||
pub date_format: String,
|
||||
}
|
||||
|
||||
/// Parser for grouping commits.
|
||||
|
@ -29,4 +29,5 @@ pub struct Release<'a> {
|
||||
pub commits: Vec<Commit<'a>>,
|
||||
#[serde(rename = "commit_id")]
|
||||
pub commit_id: Option<String>,
|
||||
pub date: Option<String>,
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ mod test {
|
||||
.to_path_buf(),
|
||||
)?;
|
||||
let commits = repository.commits()?;
|
||||
let last_commit = AppCommit::from(commits.first().unwrap().clone());
|
||||
let last_commit = AppCommit::from(&commits.first().unwrap().clone());
|
||||
assert_eq!(get_last_commit_hash()?, last_commit.id);
|
||||
if let Err(e) = last_commit.into_conventional() {
|
||||
match e {
|
||||
|
@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
"""
|
||||
|
||||
body = """
|
||||
## {% if version %}Release {{ version }}{% else %}[unreleased]{% endif %}
|
||||
## {% if version %}[{{ version }}] - {{ date }}{% else %}[unreleased]{% endif %}
|
||||
{% for group, commits in commits | group_by(attribute="group") %}
|
||||
### {{ group | capitalize}}
|
||||
{% for commit in commits %}
|
||||
@ -27,3 +27,5 @@ group_parsers = [
|
||||
filter_group = false
|
||||
|
||||
tag_pattern = "v[0-9]*"
|
||||
|
||||
date_format = "%Y-%m-%d"
|
||||
|
Loading…
Reference in New Issue
Block a user