feat: record adapter run ID in run log; add CSS to run log

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2024-12-09 08:27:45 +02:00
parent c4bb071a95
commit 27712152d9
4 changed files with 28 additions and 6 deletions
+2 -1
View File
@@ -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"),
+1 -1
View File
@@ -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);
+4 -3
View File
@@ -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<Self, RunError> {
let run_log = RunLog::new(run_log_filename);
pub fn new(run_id: RunId, run_dir: &Path, run_log_filename: &Path) -> Result<Self, RunError> {
let mut run_log = RunLog::new(run_log_filename);
run_log.adapter_run_id(run_id);
Ok(Self {
run_log,
+21 -1
View File
@@ -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<Command>,
runspec: Option<RunSpec>,
runspec_error: Option<String>,
adapter_run_id: Option<RunId>,
}
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: ")