From 15d11edac728ebe51dfbc206ccc6574bc6218328 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 28 Jan 2024 01:19:46 +0100 Subject: [PATCH] we got basic git log --- Cargo.toml | 1 + src/changelog/mod.rs | 14 +++++++++++--- src/error.rs | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 88b92a0..0714396 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/changelog/mod.rs b/src/changelog/mod.rs index a53c543..6a06e77 100644 --- a/src/changelog/mod.rs +++ b/src/changelog/mod.rs @@ -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 { 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)) } } diff --git a/src/error.rs b/src/error.rs index 99d635a..32e5d7b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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), }