mirror of
https://github.com/orhun/git-cliff.git
synced 2024-11-29 05:14:41 +03:00
feat(config): changelog for the last n commits (#116)
* feat(config): changelog for the last n commits Adds a additional configuration variable `limit_commits` to the configuration struct. `limit_commits` can be set to a positive integer number to limit the commits contained in the generated changelog. Also adjusts the default config file to contain `limit_commits` as a commented out line. Extends documentation in README.md to also cover the introduced configuration value. issue: https://github.com/orhun/git-cliff/issues/102 * test(fixture): add test fixture for limiting commits Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
parent
1c98995454
commit
0c7769b52f
30
.github/fixtures/test-limit-commits/cliff.toml
vendored
Normal file
30
.github/fixtures/test-limit-commits/cliff.toml
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
[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://tera.netlify.app/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
|
||||
"""
|
||||
# remove the leading and trailing whitespace from the template
|
||||
trim = true
|
||||
# changelog footer
|
||||
footer = """
|
||||
<!-- generated by git-cliff -->
|
||||
"""
|
||||
|
||||
[git]
|
||||
limit_commits = 2
|
8
.github/fixtures/test-limit-commits/commit.sh
vendored
Executable file
8
.github/fixtures/test-limit-commits/commit.sh
vendored
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1 (#1)"
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "refactor: move classes"
|
||||
git tag v0.1.0
|
15
.github/fixtures/test-limit-commits/expected.md
vendored
Normal file
15
.github/fixtures/test-limit-commits/expected.md
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.1.0] - 2022-04-05
|
||||
|
||||
### Fix
|
||||
|
||||
- Fix feature 1 (#1)
|
||||
|
||||
### Refactor
|
||||
|
||||
- Move classes
|
||||
|
||||
<!-- generated by git-cliff -->
|
39
README.md
39
README.md
@ -469,6 +469,7 @@ link_parsers = [
|
||||
{ pattern = "#(\\d+)", href = "https://github.com/orhun/git-cliff/issues/$1"},
|
||||
{ pattern = "RFC(\\d+)", text = "ietf-rfc$1", href = "https://datatracker.ietf.org/doc/html/rfc$1"},
|
||||
]
|
||||
limit_commits = 42
|
||||
```
|
||||
|
||||
#### conventional_commits
|
||||
@ -652,6 +653,12 @@ Examples:
|
||||
- `{ pattern = "RFC(\\d+)", text = "ietf-rfc$1", href = "https://datatracker.ietf.org/doc/html/rfc$1"}`,
|
||||
- Extract mentions of IETF RFCs and generate URLs linking to them. It also rewrites the text as "ietf-rfc...".
|
||||
|
||||
#### limit_commits
|
||||
|
||||
`limit_commits` is a **optional** positive integer number that limits the number of included commits in the generated changelog.
|
||||
|
||||
`limit_commits` is not part of the default configuration.
|
||||
|
||||
## Project Integration
|
||||
|
||||
### Rust
|
||||
@ -1018,6 +1025,38 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
</details>
|
||||
|
||||
#### [Limited Commits](./examples/limitedcommits.toml)
|
||||
|
||||
<details>
|
||||
<summary>Raw Output</summary>
|
||||
|
||||
```
|
||||
## [unreleased]
|
||||
### Feat
|
||||
- Support multiple file formats
|
||||
- Use cache while fetching pages
|
||||
|
||||
## [1.0.1] - 2021-07-18
|
||||
### Chore
|
||||
- Add release script
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Rendered Output</summary>
|
||||
|
||||
## [unreleased]
|
||||
### Feat
|
||||
- Support multiple file formats
|
||||
- Use cache while fetching pages
|
||||
|
||||
## [1.0.1] - 2021-07-18
|
||||
### Chore
|
||||
- Add release script
|
||||
|
||||
</details>
|
||||
|
||||
#### [Detailed](./examples/detailed.toml)
|
||||
|
||||
<details>
|
||||
|
@ -66,3 +66,5 @@ ignore_tags = ""
|
||||
date_order = false
|
||||
# sort the commits inside sections by oldest/newest order
|
||||
sort_commits = "oldest"
|
||||
# limit the number of commits included in the changelog.
|
||||
# limit_commits = 42
|
||||
|
21
examples/limitedcommits.toml
Normal file
21
examples/limitedcommits.toml
Normal file
@ -0,0 +1,21 @@
|
||||
# configuration file for git-cliff (0.1.0)
|
||||
|
||||
[changelog]
|
||||
# template for the changelog body
|
||||
# https://tera.netlify.app/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
|
||||
"""
|
||||
|
||||
[git]
|
||||
limit_commits = 3
|
@ -69,6 +69,8 @@ pub struct GitConfig {
|
||||
pub date_order: Option<bool>,
|
||||
/// Sorting of the commits inside sections.
|
||||
pub sort_commits: Option<String>,
|
||||
/// Limit the number of commits included in the changelog.
|
||||
pub limit_commits: Option<usize>,
|
||||
}
|
||||
|
||||
/// Parser for grouping commits.
|
||||
|
@ -91,6 +91,7 @@ fn generate_changelog() -> Result<()> {
|
||||
text: Some(String::from("$1")),
|
||||
},
|
||||
]),
|
||||
limit_commits: None,
|
||||
};
|
||||
|
||||
let releases = vec![
|
||||
|
@ -265,6 +265,7 @@ mod test {
|
||||
date_order: Some(false),
|
||||
sort_commits: Some(String::from("oldest")),
|
||||
link_parsers: None,
|
||||
limit_commits: None,
|
||||
},
|
||||
};
|
||||
let test_release = Release {
|
||||
|
@ -217,8 +217,11 @@ pub fn run(mut args: Opt) -> Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
let commits =
|
||||
let mut commits =
|
||||
repository.commits(commit_range, args.include_path, args.exclude_path)?;
|
||||
if let Some(commit_limit_value) = config.git.limit_commits {
|
||||
commits = commits.drain(..commit_limit_value).collect();
|
||||
}
|
||||
|
||||
// Update tags.
|
||||
if let Some(tag) = args.tag {
|
||||
|
Loading…
Reference in New Issue
Block a user