From e446e2f0e84364b731566cdfbbf3d7d6b9648b0e Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Fri, 13 Sep 2024 21:03:11 +0200 Subject: [PATCH] Display the artifact file suffix/type in the "db jobs" output This adds a new column ("Type") to the table that "butido db jobs" outputs. It works under the assumption that the artifact file names indicate the type of artifact via a file name extension [0] (i.e., using the format "{name}.{type}"). The fallback values are "-" if no artifact is available (build failures, aborted jobs, etc. - that's also why we're using LEFT JOIN) or "?" (for unknown) if no file name extension was detected. This resolves #391. [0]: https://en.wikipedia.org/wiki/Filename_extension Signed-off-by: Michael Weiss --- src/commands/db.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/commands/db.rs b/src/commands/db.rs index 108f9539..b21f5f4e 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -491,7 +491,7 @@ fn jobs( ) -> Result<()> { let csv = matches.get_flag("csv"); let hdrs = crate::commands::util::mk_header(vec![ - "Submit", "Job", "Time", "Host", "Ok?", "Package", "Version", "Distro", + "Submit", "Job", "Time", "Host", "Ok?", "Package", "Version", "Distro", "Type", ]); let mut conn = conn_cfg.establish_connection()?; let older_than_filter = get_date_filter("older_than", matches)?; @@ -502,6 +502,7 @@ fn jobs( .inner_join(schema::endpoints::table) .inner_join(schema::packages::table) .inner_join(schema::images::table) + .left_outer_join(schema::artifacts::table) .into_boxed(); if let Some(submit_uuid) = matches.get_one::("submit_uuid") { @@ -574,14 +575,25 @@ fn jobs( models::Endpoint, models::Package, models::Image, + Option, )>(&mut conn)? .into_iter() .rev() // required for the --limit implementation - .map(|(job, submit, ep, package, image)| { + .map(|(job, submit, ep, package, image, artifact)| { let success = is_job_successfull(&job)? .map(|b| if b { "yes" } else { "no" }) .map(String::from) .unwrap_or_else(|| String::from("?")); + let artifact_type = if let Some(artifact) = artifact { + artifact + .path + .split(".") + .last() + .map(str::to_uppercase) + .unwrap_or(String::from("?")) + } else { + String::from("-") + }; Ok(vec![ submit.uuid.to_string(), @@ -592,6 +604,7 @@ fn jobs( package.name, package.version, image_name_lookup.shorten(&image.name), + artifact_type, ]) }) .collect::>>()?;