Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
feat: add patch revisions to report pages
Merged liw opened 2 years ago

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

refactor: pagegen.rs

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

7 files changed +82 -24 3285c0d4 10bdac07
modified src/bin/pagegen.rs
@@ -1,31 +1,31 @@
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},
};

+
const DOMAIN: &str = "radicle.liw.fi";
+
const RID_1: &str = "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5";
+
const COMMIT_1: &str = "a48081f2717f069d456ec09f31d9e639b232dbed";
+
const USERID_1: &str = "J. Random Hacker <jrh@example.com>";
+
const AUTHOR_DID_3: &str = "did:key:z6MkgEMYod7Hxfy9qCvDv5hYHkZ4ciWmLFgfvm3Wn1b2w2FV";
+

const DIR: &str = "html";

fn main() -> Result<(), PageError> {
-
    let mut page = PageBuilder::default()
-
        .node_alias("radicle.liw.fi")
-
        .build()?;
+
    let mut page = PageBuilder::default().node_alias(DOMAIN).build()?;

-
    let rid1 = RepoId::from_urn("rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5").unwrap();
-
    let alias1 = "heartwood";
+
    let rid1 = rid(RID_1);
    let mut run1 = Run::new(
        rid1,
-
        alias1,
-
        Whence::branch(
-
            "master",
-
            Oid::from_str("a48081f2717f069d456ec09f31d9e639b232dbed").unwrap(),
-
            Some("J. Random Hacker <jrh@example.com>"),
-
        ),
+
        "heartwood",
+
        Whence::branch("master", oid(COMMIT_1), Some(USERID_1)),
        "2024-02-27T18:29:25+02:00".into(),
    );
    run1.set_adapter_run_id(RunId::default());
@@ -39,10 +39,18 @@ fn main() -> Result<(), PageError> {

    let mut run3 = Run::new(
        rid1,
-
        alias1,
+
        "heartwood",
        Whence::patch(
-
            Oid::from_str("60abd513e0fb858c0dfe95ad6c4aaeace9c25d60").unwrap(),
-
            Oid::from_str("091f7b7e986d05381718e2aeed2497c55dd0179a").unwrap(),
+
            oid(COMMIT_1),
+
            oid(COMMIT_1),
+
            Revision {
+
                id: oid(COMMIT_1),
+
                author: author(AUTHOR_DID_3),
+
                description: "Dummy patch description".into(),
+
                base: oid(COMMIT_1),
+
                oid: oid(COMMIT_1),
+
                timestamp: 0,
+
            },
            Some("Helpful Person <helpful@example.com>"),
        ),
        "2024-02-27T18:29:09+02:00".into(),
@@ -59,7 +67,7 @@ fn main() -> Result<(), PageError> {
        alias2,
        Whence::branch(
            "master",
-
            Oid::from_str("79469d57841632ec4c0041f564e0b2b024abe7ec").unwrap(),
+
            oid(COMMIT_1),
            Some("J. Random Hacker <random@example.com>"),
        ),
        "2024-02-27T18:29:25+02:00".into(),
@@ -73,3 +81,22 @@ fn main() -> Result<(), PageError> {

    Ok(())
}
+

+
fn rid(urn: &str) -> RepoId {
+
    RepoId::from_urn(urn).unwrap()
+
}
+

+
fn oid(commit_id: &str) -> Oid {
+
    Oid::from_str(commit_id).unwrap()
+
}
+

+
fn did(did: &str) -> Did {
+
    Did::from_str(did).unwrap()
+
}
+

+
fn author(id: &str) -> Author {
+
    Author {
+
        id: did(id),
+
        alias: None,
+
    }
+
}
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()),
        }