we got basic git log
cargo devel CI / cargo CI (push) Successful in 4m17s Details

This commit is contained in:
Christoph J. Scherr 2024-01-28 01:19:46 +01:00
parent d31befe195
commit 15d11edac7
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
3 changed files with 24 additions and 6 deletions

View File

@ -28,6 +28,7 @@ git2 = "0.18.1"
libpt = { version = "0.3.11", features = ["log"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_yaml = "0.9.30"
tempfile = "3.9.0"
thiserror = "1.0.56"
url = { version = "2.5.0", features = ["serde"] }

View File

@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, process::Command};
use crate::{config::Config, error::*};
@ -11,7 +11,7 @@ pub struct Changelog {
impl Changelog {
pub fn build(cfg: &Config) -> Result<Self> {
if !cfg.yaml.changelog.enable {
return Err(ConfigError::IsDisabledButUsed("changelog").into());
return Err(ChangelogError::IsDisabledButUsed.into());
}
let git_log = Self::make_git_log(cfg)?;
Ok(Changelog { git_log })
@ -21,7 +21,15 @@ impl Changelog {
if !cfg.yaml.changelog.enable {
return Ok(None);
}
Ok(Some(format!("todo")))
let mut cmd = Command::new("git");
cmd.arg("log").arg("--oneline").arg("--decorate");
let out = cmd.output()?;
// FIXME: this does not catch fancy colors
let buf = String::from_utf8(out.stdout).map_err(|err|{
ChangelogError::GitUTF8Error(err)
})?;
Ok(Some(buf))
}
}

View File

@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{path::PathBuf, string::FromUtf8Error};
use anyhow;
use thiserror::Error;
@ -18,8 +18,19 @@ pub enum Error {
Other(#[from] anyhow::Error),
#[error("Yaml error")]
SerdeYaml(#[from] serde_yaml::Error),
#[error("Could not generate the changelog")]
ChangelogError(#[from] ChangelogError),
}
#[derive(Error, Debug)]
pub enum ChangelogError {
#[error("changelog has 'enabled = false' in the yaml config")]
IsDisabledButUsed,
#[error("error while using `git log`, is git installed?")]
GitCommandError,
#[error("error while using `git log`, could not format stdout with utf8")]
GitUTF8Error(#[from] FromUtf8Error),
}
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("could not find git repository")]
@ -30,8 +41,6 @@ pub enum ConfigError {
YamlFileIsNotFile,
#[error("api {0:?} provides both a `pass` and a `pass_file`")]
YamlApiAuthBothPass(ApiAuth),
#[error("{0} has 'enabled = false' in the yaml config")]
IsDisabledButUsed(&'static str),
#[error("password provided as file, but does not exist: {0}")]
PassFileDoesNotExist(PathBuf),
}