1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-08-16 18:30:30 +03:00

Compare commits

...

6 Commits

Author SHA1 Message Date
tison
fc10921509
Merge cc2b748060 into e7807e13c4 2024-06-25 23:41:42 +03:00
Orhun Parmaksız
e7807e13c4
feat(context): add repository path to template context (#721) 2024-06-25 23:41:37 +03:00
tison
cc2b748060
fixup
Signed-off-by: tison <wander4096@gmail.com>
2024-06-09 10:18:57 +08:00
tison
f219ebd68a
add fixures tags
Signed-off-by: tison <wander4096@gmail.com>
2024-06-09 10:03:23 +08:00
tison
1853a5ce5c
Merge branch 'main' into support-count-tags 2024-06-09 09:59:02 +08:00
tison
63cffa7f9d
feat: support count_tags option
Signed-off-by: tison <wander4096@gmail.com>
2024-04-10 07:16:08 +08:00
13 changed files with 123 additions and 17 deletions

View File

@ -0,0 +1,34 @@
[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true
[git]
# regex for skipping tags
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = "v.*-beta.*"
count_tags = "v0.2.0"

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add skip feature"
git tag v0.1.0-beta.1
GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add feature 1"
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: fix feature 1"
git tag v0.1.0
GIT_COMMITTER_DATE="2021-01-23 01:23:48" git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0-beta.1
GIT_COMMITTER_DATE="2021-01-23 01:23:49" git commit --allow-empty -m "feat: add feature 3"
git tag v0.2.0

View File

@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.2.0] - 2021-01-23
### Feat
- Add feature 1
- Fix feature 1
- Add feature 2
- Add feature 3
<!-- generated by git-cliff -->

View File

@ -22,6 +22,7 @@ jobs:
- fixtures-name: test-gitea-integration
- fixtures-name: test-bitbucket-integration
- fixtures-name: test-ignore-tags
- fixtures-name: test-invert-ignore-tags
- fixtures-name: test-topo-order
command: --latest
- fixtures-name: test-date-order

View File

@ -613,7 +613,7 @@ mod test {
header: Some(String::from("# Changelog")),
body: Some(String::from(
r#"{% if version %}
## Release [{{ version }}] - {{ timestamp | date(format="%Y-%m-%d") }}
## Release [{{ version }}] - {{ timestamp | date(format="%Y-%m-%d") }} - ({{ repository }})
{% if commit_id %}({{ commit_id }}){% endif %}{% else %}
## Unreleased{% endif %}
{% for group, commits in commits | group_by(attribute="group") %}
@ -784,6 +784,7 @@ mod test {
tag_pattern: None,
skip_tags: Regex::new("v3.*").ok(),
ignore_tags: None,
count_tags: None,
topo_order: Some(false),
sort_commits: Some(String::from("oldest")),
link_parsers: None,
@ -881,6 +882,7 @@ mod test {
commit_id: Some(String::from("0bc123")),
timestamp: 50000000,
previous: None,
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: crate::remote::RemoteReleaseMetadata {
contributors: vec![],
@ -941,6 +943,7 @@ mod test {
commit_id: None,
timestamp: 1000,
previous: Some(Box::new(test_release)),
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: crate::remote::RemoteReleaseMetadata {
contributors: vec![],
@ -974,7 +977,7 @@ mod test {
String::from(
r#"# Changelog
## Release [v1.1.0] - 1970-01-01
## Release [v1.1.0] - 1970-01-01 - (/root/repo)
### Bug Fixes
@ -992,7 +995,7 @@ mod test {
#### ui
- do exciting stuff
## Release [v1.0.0] - 1971-08-02
## Release [v1.0.0] - 1971-08-02 - (/root/repo)
(0bc123)
### Bug Fixes
@ -1117,7 +1120,7 @@ chore(deps): fix broken deps
#### app
- merge #5
## Release [v1.0.0] - 1971-08-02
## Release [v1.0.0] - 1971-08-02 - (/root/repo)
(0bc123)
### Bug Fixes

View File

@ -109,6 +109,9 @@ pub struct GitConfig {
/// Regex to ignore matched tags.
#[serde(with = "serde_regex", default)]
pub ignore_tags: Option<Regex>,
/// Regex to count matched tags.
#[serde(with = "serde_regex", default)]
pub count_tags: Option<Regex>,
/// Whether to sort tags topologically.
pub topo_order: Option<bool>,
/// Sorting of the commits inside sections.

View File

@ -20,30 +20,32 @@ use serde::{
#[serde(rename_all = "camelCase")]
pub struct Release<'a> {
/// Release version, git tag.
pub version: Option<String>,
pub version: Option<String>,
/// git tag's message.
pub message: Option<String>,
pub message: Option<String>,
/// Commits made for the release.
pub commits: Vec<Commit<'a>>,
pub commits: Vec<Commit<'a>>,
/// Commit ID of the tag.
#[serde(rename = "commit_id")]
pub commit_id: Option<String>,
pub commit_id: Option<String>,
/// Timestamp of the release in seconds, from epoch.
pub timestamp: i64,
pub timestamp: i64,
/// Previous release.
pub previous: Option<Box<Release<'a>>>,
pub previous: Option<Box<Release<'a>>>,
/// Repository path.
pub repository: Option<String>,
/// Contributors.
#[cfg(feature = "github")]
pub github: RemoteReleaseMetadata,
pub github: RemoteReleaseMetadata,
/// Contributors.
#[cfg(feature = "gitlab")]
pub gitlab: RemoteReleaseMetadata,
pub gitlab: RemoteReleaseMetadata,
/// Contributors.
#[cfg(feature = "gitea")]
pub gitea: RemoteReleaseMetadata,
pub gitea: RemoteReleaseMetadata,
/// Contributors.
#[cfg(feature = "bitbucket")]
pub bitbucket: RemoteReleaseMetadata,
pub bitbucket: RemoteReleaseMetadata,
}
#[cfg(feature = "github")]
@ -187,6 +189,7 @@ mod test {
version: Some(String::from(version)),
..Default::default()
})),
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: crate::remote::RemoteReleaseMetadata {
contributors: vec![],
@ -395,6 +398,7 @@ mod test {
version: Some(String::from("1.0.0")),
..Default::default()
})),
repository: Some(String::from("/root/repo")),
github: RemoteReleaseMetadata {
contributors: vec![],
},
@ -681,6 +685,7 @@ mod test {
version: Some(String::from("1.0.0")),
..Default::default()
})),
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: RemoteReleaseMetadata {
contributors: vec![],
@ -1025,6 +1030,7 @@ mod test {
version: Some(String::from("1.0.0")),
..Default::default()
})),
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: RemoteReleaseMetadata {
contributors: vec![],

View File

@ -32,7 +32,9 @@ static TAG_SIGNATURE_REGEX: Lazy<Regex> = lazy_regex!(
///
/// [`Repository`]: GitRepository
pub struct Repository {
inner: GitRepository,
inner: GitRepository,
/// Repository path.
pub path: PathBuf,
}
impl Repository {
@ -40,7 +42,8 @@ impl Repository {
pub fn init(path: PathBuf) -> Result<Self> {
if path.exists() {
Ok(Self {
inner: GitRepository::open(path)?,
inner: GitRepository::open(&path)?,
path,
})
} else {
Err(Error::IoError(io::Error::new(

View File

@ -206,6 +206,7 @@ mod test {
commit_id: None,
timestamp: 0,
previous: None,
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: crate::remote::RemoteReleaseMetadata {
contributors: vec![],

View File

@ -118,6 +118,7 @@ fn generate_changelog() -> Result<()> {
tag_pattern: None,
skip_tags: None,
ignore_tags: None,
count_tags: None,
topo_order: None,
sort_commits: None,
link_parsers: Some(vec![
@ -194,6 +195,7 @@ fn generate_changelog() -> Result<()> {
commit_id: None,
timestamp: 0,
previous: None,
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: git_cliff_core::remote::RemoteReleaseMetadata {
contributors: vec![],
@ -235,6 +237,7 @@ fn generate_changelog() -> Result<()> {
commit_id: None,
timestamp: 0,
previous: None,
repository: Some(String::from("/root/repo")),
#[cfg(feature = "github")]
github: git_cliff_core::remote::RemoteReleaseMetadata {
contributors: vec![],

View File

@ -88,6 +88,7 @@ fn process_repository<'a>(
let mut tags = repository.tags(&config.git.tag_pattern, args.topo_order)?;
let skip_regex = config.git.skip_tags.as_ref();
let ignore_regex = config.git.ignore_tags.as_ref();
let count_tags = config.git.count_tags.as_ref();
tags = tags
.into_iter()
.filter(|(_, tag)| {
@ -96,6 +97,16 @@ fn process_repository<'a>(
// Keep skip tags to drop commits in the later stage.
let skip = skip_regex.map(|r| r.is_match(name)).unwrap_or_default();
let count = count_tags
.map(|r| {
let count_tag = r.is_match(name);
if count_tag {
trace!("Counting release: {}", name)
}
count_tag
})
.unwrap_or(true);
let ignore = ignore_regex
.map(|r| {
if r.as_str().trim().is_empty() {
@ -110,7 +121,7 @@ fn process_repository<'a>(
})
.unwrap_or_default();
skip || !ignore
skip || (count && !ignore)
})
.collect();
@ -245,6 +256,8 @@ fn process_repository<'a>(
for git_commit in commits.iter().rev() {
let commit = Commit::from(git_commit);
let commit_id = commit.id.to_string();
releases[release_index].repository =
Some(repository.path.to_string_lossy().to_string());
if args.sort == Sort::Newest {
releases[release_index].commits.insert(0, commit);
} else {

View File

@ -62,6 +62,7 @@ following context is generated to use for templating:
],
"commit_id": "a440c6eb26404be4877b7e3ad592bfaa5d4eb210 (release commit)",
"timestamp": 1625169301,
"repository": "/path/to/repository",
"previous": {
"version": "previous release"
}
@ -156,6 +157,7 @@ If [`conventional_commits`](/docs/configuration/git#conventional_commits) is set
],
"commit_id": "a440c6eb26404be4877b7e3ad592bfaa5d4eb210 (release commit)",
"timestamp": 1625169301,
"repository": "/path/to/repository",
"previous": {
"version": "previous release"
}

View File

@ -11,3 +11,11 @@ git cliff --repository path1 path2
```
Note that the changelog will be generated using the merged history of the given repositories.
:::tip
You can use the `{{ repository }}` variable in the template to display which release belongs to which repository.
See [context](/docs/templating/context) for more information.
:::