Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
feat: show JSON status on HTML report front page
Merged liw opened 2 years ago

Also, prettify the JSON.

Signed-off-by: Lars Wirzenius liw@liw.fi

1 file changed +21 -5 0935bbdb 3285c0d4
modified src/pages.rs
@@ -126,10 +126,8 @@ impl PageData {
        doc.push_to_body(
            &Element::new(Tag::P)
                .with_text("Last updated: ")
-
                .with_text(&self.timestamp),
-
        );
-
        doc.push_to_body(
-
            &Element::new(Tag::P)
+
                .with_text(&self.timestamp)
+
                .with_child(Element::new(Tag::Br))
                .with_text("CI broker version: ")
                .with_text(self.ci_broker_version)
                .with_text(" (commit ")
@@ -137,6 +135,18 @@ impl PageData {
                .with_text(")"),
        );

+
        let status = StatusData::from(self).as_json();
+
        doc.push_to_body(
+
            &Element::new(Tag::P).with_child(
+
                Element::new(Tag::A)
+
                    .with_attribute("href", "status.json")
+
                    .with_text("status.json:"),
+
            ),
+
        );
+
        doc.push_to_body(
+
            &Element::new(Tag::Blockquote).with_child(Element::new(Tag::Pre).with_text(&status)),
+
        );
+

        doc.push_to_body(&Element::new(Tag::H2).with_text("Repositories"));

        doc.push_to_body(&Element::new(Tag::P).with_text("Latest CI run for each repository."));
@@ -455,7 +465,7 @@ impl StatusPage {
        // contention.
        let status = {
            let data = self.lock();
-
            serde_json::to_string(&StatusData::from(&*data)).unwrap()
+
            StatusData::from(&*data).as_json()
        };

        write(filename, status).unwrap();
@@ -482,6 +492,12 @@ struct StatusData {
    latest_ci_run: Option<Run>,
}

+
impl StatusData {
+
    fn as_json(&self) -> String {
+
        serde_json::to_string_pretty(self).unwrap()
+
    }
+
}
+

impl From<&PageData> for StatusData {
    fn from(page: &PageData) -> Self {
        Self {