changelog until last tag
cargo devel CI / cargo CI (push) Successful in 4m14s Details

This commit is contained in:
Christoph J. Scherr 2024-01-28 01:33:43 +01:00
parent 15d11edac7
commit 6701e86c38
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
2 changed files with 25 additions and 2 deletions

View File

@ -22,15 +22,36 @@ impl Changelog {
return Ok(None); return Ok(None);
} }
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.arg("log").arg("--oneline").arg("--decorate"); cmd.arg("log").arg(format!("{}..HEAD", Self::get_last_tag()?,)).arg("--oneline");
let out = cmd.output()?; let out = cmd.output()?;
// FIXME: this does not catch fancy colors // FIXME: this does not catch fancy colors
let buf = String::from_utf8(out.stdout).map_err(|err|{ let buf = String::from_utf8(out.stdout).map_err(|err|{
ChangelogError::GitUTF8Error(err) ChangelogError::GitUTF8Error(err)
})?; })?;
if !out.status.success() {
return Err(
ChangelogError::GitBadStatus(out.status, buf).into()
)
}
Ok(Some(buf)) Ok(Some(buf))
} }
fn get_last_tag() -> Result<String> {
let mut cmd = Command::new("git");
cmd.arg("describe").arg("--tags").arg("--abbrev=0");
let out = cmd.output()?;
let buf = String::from_utf8(out.stdout).map_err(|err|{
ChangelogError::GitUTF8Error(err)
})?;
if !out.status.success() {
return Err(
ChangelogError::GitBadStatus(out.status, buf).into()
)
}
let buf = buf.replace("\n", "");
return Ok(buf)
}
} }
impl Display for Changelog { impl Display for Changelog {

View File

@ -1,4 +1,4 @@
use std::{path::PathBuf, string::FromUtf8Error}; use std::{path::PathBuf, process::ExitStatus, string::FromUtf8Error};
use anyhow; use anyhow;
use thiserror::Error; use thiserror::Error;
@ -30,6 +30,8 @@ pub enum ChangelogError {
GitCommandError, GitCommandError,
#[error("error while using `git log`, could not format stdout with utf8")] #[error("error while using `git log`, could not format stdout with utf8")]
GitUTF8Error(#[from] FromUtf8Error), GitUTF8Error(#[from] FromUtf8Error),
#[error("git exited with status {0}: {1}")]
GitBadStatus(ExitStatus, String),
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum ConfigError { pub enum ConfigError {