From 27712152d999709ef5b67d8333078946e05d63db Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 9 Dec 2024 08:27:45 +0200 Subject: [PATCH] feat: record adapter run ID in run log; add CSS to run log Signed-off-by: Lars Wirzenius --- src/bin/run_log.rs | 3 ++- src/engine.rs | 2 +- src/run.rs | 7 ++++--- src/runlog.rs | 22 +++++++++++++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/bin/run_log.rs b/src/bin/run_log.rs index 413ce0b..18c4534 100644 --- a/src/bin/run_log.rs +++ b/src/bin/run_log.rs @@ -1,12 +1,13 @@ use std::{path::Path, time::SystemTime}; -use radicle_ci_broker::msg::{Oid, RepoId}; +use radicle_ci_broker::msg::{Oid, RepoId, RunId}; use radicle_native_ci::{runlog::RunLog, runspec::RunSpec}; /// The main program. fn main() { let mut run_log = RunLog::new(Path::new("testlog.html")); + run_log.adapter_run_id(RunId::from("plugh")); run_log.title("Some Title"); run_log.rid( RepoId::from_urn("rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE").expect("rid"), diff --git a/src/engine.rs b/src/engine.rs index 6835212..dfbe984 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -214,7 +214,7 @@ impl Engine { } // Create and set up the run. - let mut run = Run::new(&run_dir, &run_log_filename)?; + let mut run = Run::new(run_id, &run_dir, &run_log_filename)?; run.set_repository(rid, name); run.set_request(req); run.set_commit(commit); diff --git a/src/run.rs b/src/run.rs index 1e78193..c00ecd5 100644 --- a/src/run.rs +++ b/src/run.rs @@ -4,7 +4,7 @@ use std::{ time::SystemTime, }; -use radicle_ci_broker::msg::{Oid, RepoId, Request}; +use radicle_ci_broker::msg::{Oid, RepoId, Request, RunId}; use crate::{ msg::NativeMessageError, @@ -35,8 +35,9 @@ pub struct Run { impl Run { /// Create a new `Run`. - pub fn new(run_dir: &Path, run_log_filename: &Path) -> Result { - let run_log = RunLog::new(run_log_filename); + pub fn new(run_id: RunId, run_dir: &Path, run_log_filename: &Path) -> Result { + let mut run_log = RunLog::new(run_log_filename); + run_log.adapter_run_id(run_id); Ok(Self { run_log, diff --git a/src/runlog.rs b/src/runlog.rs index 20861b3..77a9da9 100644 --- a/src/runlog.rs +++ b/src/runlog.rs @@ -6,13 +6,15 @@ use std::{ use html_page::{Element, HtmlPage, Tag}; use time::{macros::format_description, OffsetDateTime}; -use radicle_ci_broker::msg::{Oid, RepoId, Request}; +use radicle_ci_broker::msg::{Oid, RepoId, Request, RunId}; use crate::{ run::RUNSPEC_PATH, runspec::{RunSpec, RunSpecError}, }; +const CSS: &str = include_str!("native-ci.css"); + #[derive(Debug, Default)] pub struct RunLog { filename: PathBuf, @@ -26,6 +28,7 @@ pub struct RunLog { commands: Vec, runspec: Option, runspec_error: Option, + adapter_run_id: Option, } impl RunLog { @@ -36,6 +39,10 @@ impl RunLog { } } + pub fn adapter_run_id(&mut self, id: RunId) { + self.adapter_run_id = Some(id); + } + pub fn title(&mut self, title: &str) { self.title = Some(title.into()); } @@ -107,9 +114,22 @@ impl RunLog { let mut doc = HtmlPage::default(); doc.push_to_head(Element::new(Tag::Title).with_text(title)); + doc.push_to_head(Element::new(Tag::Style).with_text(CSS)); doc.push_to_body(Element::new(Tag::H1).with_text(title)); + eprintln!("adapter run id: {:?}", self.adapter_run_id); let ul = Element::new(Tag::Ul) + .with_child( + Element::new(Tag::Li) + .with_text("Adapter run ID: ") + .with_child(if let Some(id) = &self.adapter_run_id { + Element::new(Tag::Span) + .with_class("run_id") + .with_text(id.as_str()) + } else { + Element::new(Tag::Span).with_class("run_id") + }), + ) .with_child( Element::new(Tag::Li) .with_text("Repository id: ")