Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
feat: record adapter run ID in run log; add CSS to run log
Lars Wirzenius committed 1 year ago
commit 27712152d999709ef5b67d8333078946e05d63db
parent c4bb071
4 files changed +28 -6
modified 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"),
modified 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);
modified 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<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,
modified 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<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,11 +114,24 @@ 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: ")
                    .with_child(Element::new(Tag::Code).with_text(&rid.to_string()))
                    .with_text(" ")