Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: make who in Whence variants optional
Lars Wirzenius committed 2 years ago
commit 4740c81c0e1796f145ce4b2b4741e571b5f98fb8
parent 1c64e2eb04f16075cedc20eb83364e491ec14dff
5 files changed +49 -16
modified src/adapter.rs
@@ -196,7 +196,7 @@ mod test {
            Whence::branch(
                "main",
                Oid::try_from("ff3099ba5de28d954c41d0b5a84316f943794ea4").unwrap(),
-
                "J. Random Hacker <random@example.com>",
+
                Some("J. Random Hacker <random@example.com>"),
            ),
            "2024-02-29T12:58:12+02:00".into(),
        )
modified src/bin/pagegen.rs
@@ -24,7 +24,7 @@ fn main() -> Result<(), PageError> {
        Whence::branch(
            "master",
            Oid::from_str("a48081f2717f069d456ec09f31d9e639b232dbed").unwrap(),
-
            "J. Random Hacker <jrh@example.com>",
+
            Some("J. Random Hacker <jrh@example.com>"),
        ),
        "2024-02-27T18:29:25+02:00".into(),
    );
@@ -43,7 +43,7 @@ fn main() -> Result<(), PageError> {
        Whence::patch(
            Oid::from_str("60abd513e0fb858c0dfe95ad6c4aaeace9c25d60").unwrap(),
            Oid::from_str("091f7b7e986d05381718e2aeed2497c55dd0179a").unwrap(),
-
            "Helpful Person <helpful@example.com>",
+
            Some("Helpful Person <helpful@example.com>"),
        ),
        "2024-02-27T18:29:09+02:00".into(),
    );
@@ -60,7 +60,7 @@ fn main() -> Result<(), PageError> {
        Whence::branch(
            "master",
            Oid::from_str("79469d57841632ec4c0041f564e0b2b024abe7ec").unwrap(),
-
            "J. Random Hacker <random@example.com>",
+
            Some("J. Random Hacker <random@example.com>"),
        ),
        "2024-02-27T18:29:25+02:00".into(),
    );
modified src/broker.rs
@@ -86,10 +86,10 @@ impl Broker {
                    }) = push
                    {
                        let who = pusher.to_string();
-
                        Whence::branch("push-event-has-no-branch-name", *after, &who)
+
                        Whence::branch("push-event-has-no-branch-name", *after, Some(who.as_str()))
                    } else if let Some(PatchEvent { action: _, patch }) = patch {
                        let who = patch.author.to_string();
-
                        Whence::patch(patch.id, patch.after, &who)
+
                        Whence::patch(patch.id, patch.after, Some(who.as_str()))
                    } else {
                        panic!("neither push not patch event");
                    };
modified src/pages.rs
@@ -194,7 +194,11 @@ impl PageData {

    fn whence_as_html(whence: &Whence) -> Element {
        match whence {
-
            Whence::Branch { name, commit, who } => Element::new(Tag::Span)
+
            Whence::Branch {
+
                name,
+
                commit,
+
                who: _,
+
            } => Element::new(Tag::Span)
                .with_text("branch ")
                .with_child(
                    Element::new(Tag::Code)
@@ -209,8 +213,16 @@ impl PageData {
                )
                .with_child(Element::new(Tag::Br))
                .with_text("from ")
-
                .with_child(Element::new(Tag::Span).with_class("who").with_text(who)),
-
            Whence::Patch { patch, commit, who } => Element::new(Tag::Span)
+
                .with_child(
+
                    Element::new(Tag::Span)
+
                        .with_class("who")
+
                        .with_text(whence.who().unwrap_or("<commit author not known>")),
+
                ),
+
            Whence::Patch {
+
                patch,
+
                commit,
+
                who: _,
+
            } => Element::new(Tag::Span)
                .with_text("patch ")
                .with_child(
                    Element::new(Tag::Code)
@@ -225,7 +237,11 @@ impl PageData {
                )
                .with_child(Element::new(Tag::Br))
                .with_text("from ")
-
                .with_child(Element::new(Tag::Span).with_class("who").with_text(who)),
+
                .with_child(
+
                    Element::new(Tag::Span)
+
                        .with_class("who")
+
                        .with_text(whence.who().unwrap_or("<patch author not known>")),
+
                ),
        }
    }

modified src/run.rs
@@ -114,29 +114,46 @@ pub enum Whence {
    Branch {
        name: String,
        commit: Oid,
-
        who: String,
+
        who: Option<String>,
    },
    Patch {
        patch: Oid,
        commit: Oid,
-
        who: String,
+
        who: Option<String>,
    },
}

impl Whence {
-
    pub fn branch(name: &str, commit: Oid, who: &str) -> Self {
+
    pub fn branch(name: &str, commit: Oid, who: Option<&str>) -> Self {
        Self::Branch {
            name: name.into(),
            commit,
-
            who: who.into(),
+
            who: who.map(|s| s.to_string()),
        }
    }

-
    pub fn patch(patch: Oid, commit: Oid, who: &str) -> Self {
+
    pub fn patch(patch: Oid, commit: Oid, who: Option<&str>) -> Self {
        Self::Patch {
            patch,
            commit,
-
            who: who.into(),
+
            who: who.map(|s| s.to_string()),
+
        }
+
    }
+
}
+

+
impl Whence {
+
    pub fn who(&self) -> Option<&str> {
+
        match self {
+
            Self::Branch {
+
                name: _,
+
                commit: _,
+
                who,
+
            } => who.as_ref().map(|x| x.as_str()),
+
            Self::Patch {
+
                patch: _,
+
                commit: _,
+
                who,
+
            } => who.as_ref().map(|x| x.as_str()),
        }
    }
}