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

Compare commits

...

3 Commits

Author SHA1 Message Date
dependabot[bot]
024cbf1a15
Merge 3d78b729a4 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
dependabot[bot]
3d78b729a4
chore(deps): bump git2 from 0.18.3 to 0.19.0
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.18.3 to 0.19.0.
- [Changelog](https://github.com/rust-lang/git2-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/git2-rs/compare/git2-0.18.3...git2-0.19.0)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-19 08:54:41 +00:00
10 changed files with 47 additions and 21 deletions

8
Cargo.lock generated
View File

@ -828,9 +828,9 @@ dependencies = [
[[package]]
name = "git2"
version = "0.18.3"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70"
checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724"
dependencies = [
"bitflags 2.5.0",
"libc",
@ -1364,9 +1364,9 @@ dependencies = [
[[package]]
name = "libgit2-sys"
version = "0.16.2+1.7.2"
version = "0.17.0+1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8"
checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224"
dependencies = [
"cc",
"libc",

View File

@ -76,7 +76,7 @@ url = "2.5.2"
dyn-clone = "1.0.17"
[dependencies.git2]
version = "0.18.3"
version = "0.19.0"
default-features = false
optional = true

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") %}
@ -881,6 +881,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 +942,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 +976,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 +994,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 +1119,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

@ -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

@ -194,6 +194,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 +236,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

@ -245,6 +245,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.
:::