Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
feat: move ToC to top, add all headings
Merged liw opened 1 year ago

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

refactor: make code to create the preamble clearer

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

1 file changed +42 -43 423d4aee 3366fc90
modified src/runlog.rs
@@ -114,75 +114,74 @@ impl RunLog {
        doc.push_to_head(Element::new(Tag::Title).with_text(title));
        doc.push_to_body(Element::new(Tag::H1).with_text(title));

-
        let mut ul = Element::new(Tag::Ul);
-
        ul.push_child(
-
            Element::new(Tag::Li)
-
                .with_text("Repository id: ")
-
                .with_child(Element::new(Tag::Code).with_text(&rid.to_string()))
-
                .with_text(" ")
-
                .with_text(repo_name),
-
        );
-
        ul.push_child(
-
            Element::new(Tag::Li)
-
                .with_text("Commit: ")
-
                .with_child(Element::new(Tag::Code).with_text(&commit.to_string())),
-
        );
-
        if let Some(branch) = &self.branch {
-
            ul.push_child(
+
        let ul = Element::new(Tag::Ul)
+
            .with_child(
+
                Element::new(Tag::Li)
+
                    .with_text("Repository id: ")
+
                    .with_child(Element::new(Tag::Code).with_text(&rid.to_string()))
+
                    .with_text(" ")
+
                    .with_text(repo_name),
+
            )
+
            .with_child(
+
                Element::new(Tag::Li)
+
                    .with_text("Commit: ")
+
                    .with_child(Element::new(Tag::Code).with_text(&commit.to_string())),
+
            )
+
            .with_child(if let Some(branch) = &self.branch {
                Element::new(Tag::Li)
                    .with_text("Branch: ")
-
                    .with_child(Element::new(Tag::Code).with_text(branch)),
-
            );
-
        }
-
        if let Some((patch, title)) = &self.patch {
-
            ul.push_child(
+
                    .with_child(Element::new(Tag::Code).with_text(branch))
+
            } else if let Some((patch, title)) = &self.patch {
                Element::new(Tag::Li)
                    .with_text("Patch: ")
                    .with_child(Element::new(Tag::Code).with_text(&patch.to_string()))
                    .with_text(" ")
-
                    .with_text(title),
+
                    .with_text(title)
+
            } else {
+
                Element::new(Tag::Span)
+
            })
+
            .with_child(
+
                Element::new(Tag::Li)
+
                    .with_text("Result: ")
+
                    .with_child(Element::new(Tag::B).with_text(self.result())),
            );
-
        }
-
        ul.push_child(
-
            Element::new(Tag::Li)
-
                .with_text("Result: ")
-
                .with_child(Element::new(Tag::B).with_text(self.result())),
-
        );
        doc.push_to_body(ul);

-
        doc.push_to_body(Element::new(Tag::H2).with_text("Request message"));
+
        let mut toc = ToC::default();
+
        let mut body = Element::new(Tag::Div);
+

+
        body.push_child(
+
            toc.push(
+
                Element::new(Tag::Span)
+
                    .with_child(Element::new(Tag::Code).with_text("Request message")),
+
            ),
+
        );
        let req = serde_json::to_string_pretty(&self.request).unwrap();
        let req = Element::new(Tag::Pre).with_text(&req);
-
        doc.push_to_body(req);
+
        body.push_child(req);

        if let Some(e) = &self.runspec_error {
            let error = Element::new(Tag::P)
                .with_text("Failed to load .radicle/native.yaml: ")
                .with_child(Element::new(Tag::Code).with_text(e));
-
            doc.push_to_body(error);
+
            body.push_child(error);
        }

        if self.timeout {
            let timeout = Element::new(Tag::P).with_text("Last command timed out");
-
            doc.push_to_body(timeout);
+
            body.push_child(timeout);
        }

        if let Some(runspec) = &self.runspec {
            let text = serde_yaml::to_string(&runspec).map_err(RunLogError::RunSpec)?;
-
            let native_yaml = Element::new(Tag::Div)
-
                .with_child(
-
                    Element::new(Tag::H2)
-
                        .with_child(Element::new(Tag::Code).with_text(RUNSPEC_PATH)),
-
                )
-
                .with_child(
-
                    Element::new(Tag::Blockquote)
-
                        .with_child(Element::new(Tag::Pre).with_text(&text)),
-
                );
-
            doc.push_to_body(native_yaml);
+
            body.push_child(toc.push(Element::new(Tag::Span).with_child(
+
                Element::new(Tag::Code).with_child(Element::new(Tag::Code).with_text(RUNSPEC_PATH)),
+
            )));
+
            body.push_child(
+
                Element::new(Tag::Blockquote).with_child(Element::new(Tag::Pre).with_text(&text)),
+
            );
        }

-
        let mut toc = ToC::default();
-
        let mut body = Element::new(Tag::Div);
        for cmd in self.commands.iter() {
            cmd.format(&mut body, &mut toc);
        }