Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat(src/pages.rs): use CI events in HTML report pages
Lars Wirzenius committed 1 year ago
commit 07612f53e9f77c08991a37d898724b337071b33a
parent d44877da78f02c9e742acc8ebe5a0f9c80afabef
1 file changed +64 -42
modified src/pages.rs
@@ -21,14 +21,15 @@ use serde::Serialize;
use time::{macros::format_description, OffsetDateTime};

use radicle::{
+
    git::ext::Oid,
    prelude::RepoId,
    storage::{ReadRepository, ReadStorage},
    Profile,
};

use crate::{
-
    db::{Db, DbError, QueuedEvent},
-
    event::{parse_ref, BrokerEvent, ParsedRef},
+
    ci_event::CiEvent,
+
    db::{Db, DbError, QueuedCiEvent},
    logger,
    msg::RunId,
    notif::NotificationReceiver,
@@ -77,9 +78,9 @@ struct PageData {
    ci_broker_git_commit: &'static str,
    node_alias: String,
    runs: HashMap<RunId, Run>,
-
    events: Vec<QueuedEvent>,
+
    events: Vec<QueuedCiEvent>,
    broker_event_counter: usize,
-
    latest_broker_event: Option<BrokerEvent>,
+
    latest_broker_event: Option<CiEvent>,
    latest_ci_run: Option<Run>,
}

@@ -160,41 +161,58 @@ impl PageData {
                    .with_child(Element::new(Tag::Th).with_text("Event")),
            );
        for event in self.events.iter() {
+
            fn render_event(repo: &RepoId, refname: &str, commit: &Oid) -> Element {
+
                Element::new(Tag::Span)
+
                    .with_child(
+
                        Element::new(Tag::Span)
+
                            .with_class("repoid")
+
                            .with_text(&repo.to_string()),
+
                    )
+
                    .with_child(Element::new(Tag::Br))
+
                    .with_child(Element::new(Tag::Span).with_class("ref").with_text(refname))
+
                    .with_child(Element::new(Tag::Br))
+
                    .with_child(
+
                        Element::new(Tag::Span)
+
                            .with_class("commit")
+
                            .with_text(&commit.to_string()),
+
                    )
+
            }
+

+
            let event_element = match event.event() {
+
                CiEvent::Shutdown => Element::new(Tag::Span).with_text("shutdown"),
+
                CiEvent::BranchCreated {
+
                    from_node: _,
+
                    repo,
+
                    branch,
+
                    tip,
+
                } => render_event(repo, branch, tip),
+
                CiEvent::BranchUpdated {
+
                    from_node: _,
+
                    repo,
+
                    branch,
+
                    tip,
+
                    old_tip: _,
+
                } => render_event(repo, branch, tip),
+
                CiEvent::BranchDeleted { repo, branch, tip } => render_event(repo, branch, tip),
+
                CiEvent::PatchCreated {
+
                    from_node: _,
+
                    repo,
+
                    patch,
+
                    new_tip,
+
                } => render_event(repo, &patch.to_string(), new_tip),
+
                CiEvent::PatchUpdated {
+
                    from_node: _,
+
                    repo,
+
                    patch,
+
                    new_tip,
+
                } => render_event(repo, &patch.to_string(), new_tip),
+
            };
+

            table.push_child(
                Element::new(Tag::Tr)
                    .with_child(Element::new(Tag::Td).with_text(&event.id().to_string()))
                    .with_child(Element::new(Tag::Td).with_text(event.timestamp()))
-
                    .with_child(
-
                        Element::new(Tag::Td).with_child(match event.event() {
-
                            BrokerEvent::Shutdown => Element::new(Tag::Span).with_text("shutdown"),
-
                            BrokerEvent::RefChanged {
-
                                rid,
-
                                name,
-
                                oid,
-
                                old: _,
-
                            } => Element::new(Tag::Span)
-
                                .with_child(
-
                                    Element::new(Tag::Span)
-
                                        .with_class("repoid")
-
                                        .with_text(&rid.to_string()),
-
                                )
-
                                .with_child(Element::new(Tag::Br))
-
                                .with_child(Element::new(Tag::Span).with_class("ref").with_text(
-
                                    &match parse_ref(name) {
-
                                        Ok(Some(ParsedRef::Push(branch))) => branch,
-
                                        Ok(Some(ParsedRef::Patch(patch))) => patch.to_string(),
-
                                        Ok(None) => "unknown".into(),
-
                                        Err(_) => "unknown".into(),
-
                                    },
-
                                ))
-
                                .with_child(Element::new(Tag::Br))
-
                                .with_child(
-
                                    Element::new(Tag::Span)
-
                                        .with_class("commit")
-
                                        .with_text(&oid.to_string()),
-
                                ),
-
                        }),
-
                    ),
+
                    .with_child(Element::new(Tag::Td).with_child(event_element)),
            );
        }
        doc.push_to_body(table);
@@ -523,19 +541,23 @@ impl StatusPage {

            // Create list of events, except ones for private
            // repositories.
-
            let events: Result<Vec<QueuedEvent>, PageError> = db
-
                .queued_events()?
+
            let events: Result<Vec<QueuedCiEvent>, PageError> = db
+
                .queued_ci_events()?
                .iter()
-
                .filter_map(|id| match db.get_queued_event(id) {
+
                .filter_map(|id| match db.get_queued_ci_event(id) {
                    Ok(Some(event)) => match event.event() {
-
                        BrokerEvent::Shutdown => Some(Ok(event)),
-
                        BrokerEvent::RefChanged { rid, .. } => {
-
                            if Self::is_public_repo(profile, rid) {
+
                        CiEvent::Shutdown => Some(Ok(event)),
+
                        CiEvent::BranchCreated { repo, .. }
+
                        | CiEvent::BranchUpdated { repo, .. }
+
                        | CiEvent::PatchCreated { repo, .. }
+
                        | CiEvent::PatchUpdated { repo, .. } => {
+
                            if Self::is_public_repo(profile, repo) {
                                Some(Ok(event))
                            } else {
                                None
                            }
                        }
+
                        _ => None,
                    },
                    Ok(None) => None, // Event is (no longer?) in database.
                    Err(_) => None,   // We ignore error here on purpose.
@@ -615,7 +637,7 @@ struct StatusData {
    broker_event_counter: usize,
    ci_broker_version: &'static str,
    ci_broker_git_commit: &'static str,
-
    latest_broker_event: Option<BrokerEvent>,
+
    latest_broker_event: Option<CiEvent>,
    latest_ci_run: Option<Run>,
    event_queue_length: usize,
}