Skip to content

Commit

Permalink
Merge pull request #10 from corebreaker/enrich-infos
Browse files Browse the repository at this point in the history
Add missing Git infos in report
  • Loading branch information
corebreaker authored May 5, 2024
2 parents 25d2275 + 7945ce6 commit 33611c5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <frederic.meyer.77@gmail.com>"]
edition = "2021"
license = "LGPL-3.0"
Expand Down
4 changes: 4 additions & 0 deletions src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ pub struct CliArgs {
#[clap(short='D', long, value_name = "dir", global = true)]
pub prune_dir: Option<Vec<PathBuf>>,

/// 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,
Expand Down
45 changes: 31 additions & 14 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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));
Expand All @@ -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!();
}
}
6 changes: 5 additions & 1 deletion src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -61,4 +61,8 @@ impl Coverage {
pub fn new_reader(&self) -> Result<Box<dyn Read>> {
Ok(Box::new(Cursor::new(serde_json::to_string(&self)?)))
}

pub fn git(&self) -> Option<&GitInfos> {
self.git.as_ref()
}
}
7 changes: 6 additions & 1 deletion src/coverralls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit 33611c5

Please sign in to comment.