mirror of
https://github.com/orhun/git-cliff.git
synced 2025-01-05 15:58:24 +03:00
feat(changelog): support generating changelog based on tagging status
This commit is contained in:
parent
ddd2fdb173
commit
2ba280839e
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -304,6 +304,7 @@ dependencies = [
|
||||
"config",
|
||||
"git-conventional",
|
||||
"git2",
|
||||
"indexmap",
|
||||
"pretty_assertions",
|
||||
"regex",
|
||||
"serde",
|
||||
@ -364,6 +365,12 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.2"
|
||||
@ -426,6 +433,16 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
|
@ -19,6 +19,7 @@ serde_derive = "1.0"
|
||||
tera = "1.9.0"
|
||||
regex = "1.5.4"
|
||||
serde_regex = "1.1.0"
|
||||
indexmap = "1.6.2"
|
||||
|
||||
[dependencies.config]
|
||||
version = "0.11.0"
|
||||
|
@ -8,7 +8,7 @@ use git2::{
|
||||
Repository as GitRepository,
|
||||
Sort,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@ -54,8 +54,8 @@ impl Repository {
|
||||
/// Parses and returns a commit-tag map.
|
||||
///
|
||||
/// It collects lightweight and annotated tags.
|
||||
pub fn tags(&self, pattern: &str) -> Result<HashMap<String, String>> {
|
||||
let mut tags = HashMap::new();
|
||||
pub fn tags(&self, pattern: &str) -> Result<IndexMap<String, String>> {
|
||||
let mut tags = IndexMap::new();
|
||||
let tag_names = self.inner.tag_names(Some(pattern))?;
|
||||
for name in tag_names.iter().flatten().map(String::from) {
|
||||
let obj = self.inner.revparse_single(&name)?;
|
||||
|
@ -35,6 +35,12 @@ pub struct Opt {
|
||||
/// Sets the tag for the latest version.
|
||||
#[structopt(short, long, env, value_name = "TAG", allow_hyphen_values = true)]
|
||||
pub tag: Option<String>,
|
||||
/// Processes the commits starting from the latest tag.
|
||||
#[structopt(short, long)]
|
||||
pub latest: bool,
|
||||
/// Processes the commits that do not belong to a tag.
|
||||
#[structopt(short, long)]
|
||||
pub unreleased: bool,
|
||||
/// Sets the commit range to process.
|
||||
pub range: Option<String>,
|
||||
}
|
||||
|
@ -27,7 +27,20 @@ fn main() -> Result<()> {
|
||||
let repository =
|
||||
Repository::init(args.repository.unwrap_or(env::current_dir()?))?;
|
||||
let mut tags = repository.tags(&config.git.tag_pattern)?;
|
||||
let commits = repository.commits(args.range)?;
|
||||
let mut commit_range = args.range;
|
||||
if args.unreleased {
|
||||
if let Some(last_tag) = tags.last().map(|(k, _)| k) {
|
||||
commit_range = Some(format!("{}..HEAD", last_tag));
|
||||
}
|
||||
} else if args.latest {
|
||||
if let (Some(tag1), Some(tag2)) = (
|
||||
tags.get_index(tags.len() - 2).map(|(k, _)| k),
|
||||
tags.get_index(tags.len() - 1).map(|(k, _)| k),
|
||||
) {
|
||||
commit_range = Some(format!("{}..{}", tag1, tag2));
|
||||
}
|
||||
}
|
||||
let commits = repository.commits(commit_range)?;
|
||||
|
||||
if let Some(tag) = args.tag {
|
||||
if let Some(commit_id) = commits.first().map(|c| c.id().to_string()) {
|
||||
|
Loading…
Reference in New Issue
Block a user