summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-03-18 12:07:59 +0200
committerLars Wirzenius <liw@liw.fi>2024-03-18 12:07:59 +0200
commit4740c81c0e1796f145ce4b2b4741e571b5f98fb8 (patch)
treefc383d89674d35d3accd1b28355451ff2461cbd9
parent1c64e2eb04f16075cedc20eb83364e491ec14dff (diff)
downloadradicle-ci-broker-4740c81c0e1796f145ce4b2b4741e571b5f98fb8.tar.gz
fix: make who in Whence variants optional
This should allow us to deal with old run record in the database. Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--src/adapter.rs2
-rw-r--r--src/bin/pagegen.rs6
-rw-r--r--src/broker.rs4
-rw-r--r--src/pages.rs24
-rw-r--r--src/run.rs29
5 files changed, 49 insertions, 16 deletions
diff --git a/src/adapter.rs b/src/adapter.rs
index b473d45..1f131bc 100644
--- a/src/adapter.rs
+++ b/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(),
)
diff --git a/src/bin/pagegen.rs b/src/bin/pagegen.rs
index e02508a..a7c9879 100644
--- a/src/bin/pagegen.rs
+++ b/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(),
);
diff --git a/src/broker.rs b/src/broker.rs
index dbc8ffb..6daa2c2 100644
--- a/src/broker.rs
+++ b/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");
};
diff --git a/src/pages.rs b/src/pages.rs
index 63fa711..35e21aa 100644
--- a/src/pages.rs
+++ b/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>")),
+ ),
}
}
diff --git a/src/run.rs b/src/run.rs
index 8a5c873..d3a00c0 100644
--- a/src/run.rs
+++ b/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()),
}
}
}