Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: add patch revisions to report pages
Lars Wirzenius committed 2 years ago
commit 42603ef31f9513d92b67d395eaab5f62fc490d04
parent 3285c0d40750b54984e6941b84fe9d432b1615aa
7 files changed +53 -9
modified src/bin/pagegen.rs
@@ -1,10 +1,11 @@
use std::{path::Path, str::FromStr};

use radicle::git::Oid;
+
use radicle::identity::Did;
use radicle::prelude::RepoId;

use radicle_ci_broker::{
-
    msg::{RunId, RunResult},
+
    msg::{Author, Revision, RunId, RunResult},
    pages::{PageBuilder, PageError},
    run::{Run, RunState, Whence},
};
@@ -37,12 +38,24 @@ fn main() -> Result<(), PageError> {
    run2.set_state(RunState::Finished);
    page.push_run(run2);

+
    let author = Author {
+
        id: Did::from_str("did:key:z6MkgEMYod7Hxfy9qCvDv5hYHkZ4ciWmLFgfvm3Wn1b2w2FV").unwrap(),
+
        alias: None,
+
    };
    let mut run3 = Run::new(
        rid1,
        alias1,
        Whence::patch(
            Oid::from_str("60abd513e0fb858c0dfe95ad6c4aaeace9c25d60").unwrap(),
            Oid::from_str("091f7b7e986d05381718e2aeed2497c55dd0179a").unwrap(),
+
            Revision {
+
                id: Oid::from_str("6569449fff99b251b2cea96cb76eaa0ea430c63e").unwrap(),
+
                author,
+
                description: "Dummy patch description".into(),
+
                base: Oid::from_str("5fce714ba55892702069e6df36666baf14c751a3").unwrap(),
+
                oid: Oid::from_str("5ae617abf096d31181496e6b5b048e81872c462f").unwrap(),
+
                timestamp: 0,
+
            },
            Some("Helpful Person <helpful@example.com>"),
        ),
        "2024-02-27T18:29:09+02:00".into(),
modified src/broker.rs
@@ -89,8 +89,13 @@ impl Broker {
                        let who = pusher.to_string();
                        Whence::branch("push-event-has-no-branch-name", *after, Some(who.as_str()))
                    } else if let Some(PatchEvent { action: _, patch }) = patch {
+
                        let revision = patch
+
                            .revisions
+
                            .last()
+
                            .ok_or(BrokerError::NoRevisions)?
+
                            .clone();
                        let who = patch.author.to_string();
-
                        Whence::patch(patch.id, patch.after, Some(who.as_str()))
+
                        Whence::patch(patch.id, patch.after, revision, Some(who.as_str()))
                    } else {
                        panic!("neither push not patch event");
                    };
modified src/error.rs
@@ -71,4 +71,8 @@ pub enum BrokerError {
    /// Database error.
    #[error(transparent)]
    Db(#[from] DbError),
+

+
    /// Patch event doesn't have any revisions.
+
    #[error("expected at least one revision in a patch event")]
+
    NoRevisions,
}
modified src/msg.rs
@@ -430,7 +430,7 @@ pub struct Repository {
}

/// Fields describing the author of a change.
-
#[derive(Debug, Clone, Serialize, Deserialize)]
+
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Author {
    /// The DID of the author. This is guaranteed to be unique.
    pub id: Did,
@@ -450,7 +450,7 @@ impl std::fmt::Display for Author {
}

/// The state of a patch.
-
#[derive(Debug, Clone, Serialize, Deserialize)]
+
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct State {
    /// State of the patch.
    pub status: String,
@@ -460,7 +460,7 @@ pub struct State {
}

/// Revision of a patch.
-
#[derive(Debug, Clone, Serialize, Deserialize)]
+
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Revision {
    /// FIXME.
    pub id: Oid,
@@ -482,8 +482,14 @@ pub struct Revision {
    pub timestamp: u64,
}

+
impl std::fmt::Display for Revision {
+
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+
        write!(f, "{}", self.id)
+
    }
+
}
+

/// Metadata about a Radicle patch.
-
#[derive(Debug, Clone, Serialize, Deserialize)]
+
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Patch {
    /// The patch id.
    pub id: Oid,
modified src/pages.rs
@@ -231,6 +231,7 @@ impl PageData {
            Whence::Patch {
                patch,
                commit,
+
                revision,
                who: _,
            } => Element::new(Tag::Span)
                .with_text("patch ")
@@ -239,7 +240,15 @@ impl PageData {
                        .with_attribute("class", "branch")
                        .with_text(&patch.to_string()),
                )
-
                .with_text(", commit ")
+
                .with_child(Element::new(Tag::Br))
+
                .with_text("revision ")
+
                .with_child(
+
                    Element::new(Tag::Code)
+
                        .with_attribute("class", "revision")
+
                        .with_text(&revision.to_string()),
+
                )
+
                .with_child(Element::new(Tag::Br))
+
                .with_text("commit ")
                .with_child(
                    Element::new(Tag::Code)
                        .with_attribute("class", "commit")
modified src/radicle-ci.css
@@ -38,6 +38,10 @@ code.commit {
    font-weight: bold;
}

+
code.revision {
+
    font-weight: bold;
+
}
+

code.repoid {
    font-weight: bold;
}
modified src/run.rs
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use radicle::git::Oid;
use radicle::prelude::RepoId;

-
use crate::msg::{RunId, RunResult};
+
use crate::msg::{Revision, RunId, RunResult};

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Run {
@@ -119,6 +119,7 @@ pub enum Whence {
    Patch {
        patch: Oid,
        commit: Oid,
+
        revision: Revision,
        who: Option<String>,
    },
}
@@ -132,10 +133,11 @@ impl Whence {
        }
    }

-
    pub fn patch(patch: Oid, commit: Oid, who: Option<&str>) -> Self {
+
    pub fn patch(patch: Oid, commit: Oid, revision: Revision, who: Option<&str>) -> Self {
        Self::Patch {
            patch,
            commit,
+
            revision,
            who: who.map(|s| s.to_string()),
        }
    }
@@ -152,6 +154,7 @@ impl Whence {
            Self::Patch {
                patch: _,
                commit: _,
+
                revision: _,
                who,
            } => who.as_ref().map(|x| x.as_str()),
        }