From 7945ce67135329d4ea06e38bb1b59c08e9f96e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Meyer?= Date: Sun, 5 May 2024 12:08:57 +0200 Subject: [PATCH] Add missing Git infos in report --- Cargo.toml | 2 +- src/cli_args.rs | 4 ++++ src/config/mod.rs | 45 +++++++++++++++++++++++++++++++-------------- src/coverage.rs | 6 +++++- src/coverralls.rs | 7 ++++++- src/main.rs | 4 ++-- 6 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7ef2da..34c44f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "coveralls" description = "Send job to Coveralls (coveralls.io)" -version = "0.1.4" +version = "0.1.5" authors = ["Frédéric Meyer "] edition = "2021" license = "LGPL-3.0" diff --git a/src/cli_args.rs b/src/cli_args.rs index ae4ea93..26eff4b 100644 --- a/src/cli_args.rs +++ b/src/cli_args.rs @@ -49,6 +49,10 @@ pub struct CliArgs { #[clap(short='D', long, value_name = "dir", global = true)] pub prune_dir: Option>, + /// Force fetching of repository informations from Git + #[clap(short='F', long, value_name = "dir", global = true)] + pub force_fetch_git_infos: bool, + /// Prune absolute paths #[clap(short='X', long, global = true)] pub prune_absolutes: bool, diff --git a/src/config/mod.rs b/src/config/mod.rs index 9880c34..873ab1a 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -9,7 +9,7 @@ mod coveralls_env; mod github_actions; use super::{Service, Env, helpers}; -use crate::cli_args::{CliArgs, CliService, CliServiceArgs}; +use crate::{cli_args::{CliArgs, CliService, CliServiceArgs}, git::GitInfos}; use itertools::Itertools; use simple_error::SimpleError; use std::{io::{Result, Error, ErrorKind}, path::PathBuf}; @@ -238,16 +238,32 @@ impl Config { self } - pub fn show(&self) { + pub fn show(&self, git: Option<&GitInfos>) { let empty = String::new(); let prune_dirs = self.param_prune_dirs.iter().map(helpers::path_to_string).join(", "); let source_prefix = self.param_src_prefix.as_ref().map(helpers::path_to_string).unwrap_or_else(String::new); + let git_id = self.git_id.as_ref().or_else(|| git.map(|v| &v.head.id)); + let git_tag = self.git_tag.as_ref(); + let git_branch = self.git_branch.as_ref().or_else(|| git.map(|v| &v.branch)); + let git_author_name = self.git_author_name.as_ref().or_else(|| git.map(|v| &v.head.author_name)); + let git_author_email = self.git_author_email.as_ref().or_else(|| git.map(|v| &v.head.author_email)); + let git_committer_name = self.git_committer_name.as_ref().or_else(|| git.map(|v| &v.head.committer_name)); + let git_committer_email = self.git_committer_email.as_ref().or_else(|| git.map(|v| &v.head.committer_email)); + let git_message = self.git_message.as_ref().or_else(|| git.map(|v| &v.head.message)); + + let git_remote_name = self.git_remote_name.as_ref() + .or_else(|| git.and_then(|v| v.remotes.get(0).map(|v| &v.name))); + + let git_remote_url = self.git_remote_url.as_ref() + .or_else(|| git.and_then(|v| v.remotes.get(0).map(|v| &v.url))); + println!("Parameters:"); println!("Prune absolute paths: {}", self.param_prune_absolutes); - println!("Prune directories: ... [{}]", prune_dirs); - println!("Source prefix: ....... [{}]", source_prefix); + println!("Prune directories: ... [{prune_dirs}]"); + println!("Source prefix: ....... [{source_prefix}]"); println!(); + println!("Configuration:"); println!("Service name: ........ {}", self.service.get_name()); println!("Repo token: .......... [{}]", self.repo_token.as_ref().unwrap_or(&empty)); @@ -261,16 +277,17 @@ impl Config { println!("Service job ID: ...... [{}]", self.service_job_id.as_ref().unwrap_or(&empty)); println!("Service job name: .... [{}]", self.service_job_name.as_ref().unwrap_or(&empty)); println!("Service job number: .. [{}]", self.service_job_number.as_ref().unwrap_or(&empty)); - println!("Git ID: .............. [{}]", self.git_id.as_ref().unwrap_or(&empty)); - println!("Git branch: .......... [{}]", self.git_branch.as_ref().unwrap_or(&empty)); - println!("Git tag: ............. [{}]", self.git_tag.as_ref().unwrap_or(&empty)); - println!("Git author name: ..... [{}]", self.git_author_name.as_ref().unwrap_or(&empty)); - println!("Git author email: .... [{}]", self.git_author_email.as_ref().unwrap_or(&empty)); - println!("Git committer name: .. [{}]", self.git_committer_name.as_ref().unwrap_or(&empty)); - println!("Git committer email: . [{}]", self.git_committer_email.as_ref().unwrap_or(&empty)); - println!("Git remote name: ..... [{}]", self.git_remote_name.as_ref().unwrap_or(&empty)); - println!("Git remote URL: ...... [{}]", self.git_remote_url.as_ref().unwrap_or(&empty)); - println!("Git message: ......... [{}]", self.git_message.as_ref().unwrap_or(&empty)); + + println!("Git ID: .............. [{}]", git_id.unwrap_or(&empty)); + println!("Git branch: .......... [{}]", git_branch.unwrap_or(&empty)); + println!("Git tag: ............. [{}]", git_tag.unwrap_or(&empty)); + println!("Git author name: ..... [{}]", git_author_name.unwrap_or(&empty)); + println!("Git author email: .... [{}]", git_author_email.unwrap_or(&empty)); + println!("Git committer name: .. [{}]", git_committer_name.unwrap_or(&empty)); + println!("Git committer email: . [{}]", git_committer_email.unwrap_or(&empty)); + println!("Git remote name: ..... [{}]", git_remote_name.unwrap_or(&empty)); + println!("Git remote URL: ...... [{}]", git_remote_url.unwrap_or(&empty)); + println!("Git message: ......... [{}]", git_message.unwrap_or(&empty)); println!(); } } diff --git a/src/coverage.rs b/src/coverage.rs index 0cd28c2..03e2eda 100644 --- a/src/coverage.rs +++ b/src/coverage.rs @@ -2,7 +2,7 @@ use super::git::GitInfos; use serde::{Deserialize, Serialize}; use std::io::{Cursor, Read, Result}; -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub(crate) struct SourceFile { pub(crate) name: String, pub(crate) source_digest: String, @@ -61,4 +61,8 @@ impl Coverage { pub fn new_reader(&self) -> Result> { Ok(Box::new(Cursor::new(serde_json::to_string(&self)?))) } + + pub fn git(&self) -> Option<&GitInfos> { + self.git.as_ref() + } } diff --git a/src/coverralls.rs b/src/coverralls.rs index 0702ee7..5c47a0f 100644 --- a/src/coverralls.rs +++ b/src/coverralls.rs @@ -9,12 +9,17 @@ impl CoverallsManager { CoverallsManager } - pub fn apply_config(&self, config: &Config, coverage: &mut Coverage) -> Result<()> { + pub fn apply_config(&self, config: &Config, coverage: &mut Coverage, mut fetch_git_infos: bool) -> Result<()> { coverage.service_name = config.service.get_name().to_string(); if let Some(infos) = coverage.git.as_mut() { infos.update(config)?; } else { + fetch_git_infos = true; + } + + if fetch_git_infos { + println!("Fetching git infos..."); let mut infos = GitInfos::default(); infos.update(config)?; diff --git a/src/main.rs b/src/main.rs index 45630bc..efab90c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,8 +29,8 @@ fn work() -> Result<()> { Coverage::from_reader(stdin())? }; - config.show(); - manager.apply_config(&config, &mut coverage)?; + manager.apply_config(&config, &mut coverage, args.force_fetch_git_infos)?; + config.show(coverage.git()); if do_send { manager.send(&coverage)?;