summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-03-18 10:54:19 +0200
committerLars Wirzenius <liw@liw.fi>2024-03-18 10:54:19 +0200
commit1c64e2eb04f16075cedc20eb83364e491ec14dff (patch)
treebed25e8aeda8a737faf568132bf1c0815aae4db6
parentc0c48fd3c09fc0b54b0482afb296f0255003ee2d (diff)
downloadradicle-ci-broker-1c64e2eb04f16075cedc20eb83364e491ec14dff.tar.gz
feat: show who made patch/commit CI is run for
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--src/adapter.rs1
-rw-r--r--src/bin/pagegen.rs3
-rw-r--r--src/broker.rs8
-rw-r--r--src/msg.rs10
-rw-r--r--src/pages.rs14
-rw-r--r--src/radicle-ci.css4
-rw-r--r--src/run.rs23
7 files changed, 51 insertions, 12 deletions
diff --git a/src/adapter.rs b/src/adapter.rs
index 30ddae1..b473d45 100644
--- a/src/adapter.rs
+++ b/src/adapter.rs
@@ -196,6 +196,7 @@ mod test {
Whence::branch(
"main",
Oid::try_from("ff3099ba5de28d954c41d0b5a84316f943794ea4").unwrap(),
+ "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 2859407..e02508a 100644
--- a/src/bin/pagegen.rs
+++ b/src/bin/pagegen.rs
@@ -24,6 +24,7 @@ fn main() -> Result<(), PageError> {
Whence::branch(
"master",
Oid::from_str("a48081f2717f069d456ec09f31d9e639b232dbed").unwrap(),
+ "J. Random Hacker <jrh@example.com>",
),
"2024-02-27T18:29:25+02:00".into(),
);
@@ -42,6 +43,7 @@ fn main() -> Result<(), PageError> {
Whence::patch(
Oid::from_str("60abd513e0fb858c0dfe95ad6c4aaeace9c25d60").unwrap(),
Oid::from_str("091f7b7e986d05381718e2aeed2497c55dd0179a").unwrap(),
+ "Helpful Person <helpful@example.com>",
),
"2024-02-27T18:29:09+02:00".into(),
);
@@ -58,6 +60,7 @@ fn main() -> Result<(), PageError> {
Whence::branch(
"master",
Oid::from_str("79469d57841632ec4c0041f564e0b2b024abe7ec").unwrap(),
+ "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 4b4381d..dbc8ffb 100644
--- a/src/broker.rs
+++ b/src/broker.rs
@@ -78,16 +78,18 @@ impl Broker {
let rid = &common.repository.id;
if let Some(adapter) = self.adapter(rid) {
let whence = if let Some(PushEvent {
- pusher: _,
+ pusher,
before: _,
after,
branch: _,
commits: _,
}) = push
{
- Whence::branch("push-event-has-no-branch-name", *after)
+ let who = pusher.to_string();
+ Whence::branch("push-event-has-no-branch-name", *after, &who)
} else if let Some(PatchEvent { action: _, patch }) = patch {
- Whence::patch(patch.id, patch.after)
+ let who = patch.author.to_string();
+ Whence::patch(patch.id, patch.after, &who)
} else {
panic!("neither push not patch event");
};
diff --git a/src/msg.rs b/src/msg.rs
index eb7200a..72799b5 100644
--- a/src/msg.rs
+++ b/src/msg.rs
@@ -439,6 +439,16 @@ pub struct Author {
pub alias: Option<Alias>,
}
+impl std::fmt::Display for Author {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.id)?;
+ if let Some(alias) = &self.alias {
+ write!(f, " ({})", alias)?;
+ }
+ Ok(())
+ }
+}
+
/// The state of a patch.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct State {
diff --git a/src/pages.rs b/src/pages.rs
index eaa4baf..63fa711 100644
--- a/src/pages.rs
+++ b/src/pages.rs
@@ -194,7 +194,7 @@ impl PageData {
fn whence_as_html(whence: &Whence) -> Element {
match whence {
- Whence::Branch { name, commit } => Element::new(Tag::Span)
+ Whence::Branch { name, commit, who } => Element::new(Tag::Span)
.with_text("branch ")
.with_child(
Element::new(Tag::Code)
@@ -206,8 +206,11 @@ impl PageData {
Element::new(Tag::Code)
.with_attribute("class", "commit")
.with_text(&commit.to_string()),
- ),
- Whence::Patch { patch, commit } => Element::new(Tag::Span)
+ )
+ .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_text("patch ")
.with_child(
Element::new(Tag::Code)
@@ -219,7 +222,10 @@ impl PageData {
Element::new(Tag::Code)
.with_attribute("class", "commit")
.with_text(&commit.to_string()),
- ),
+ )
+ .with_child(Element::new(Tag::Br))
+ .with_text("from ")
+ .with_child(Element::new(Tag::Span).with_class("who").with_text(who)),
}
}
diff --git a/src/radicle-ci.css b/src/radicle-ci.css
index 09b5a94..85754c5 100644
--- a/src/radicle-ci.css
+++ b/src/radicle-ci.css
@@ -52,3 +52,7 @@ span.running {
span.finished {
}
+
+span.who {
+ font-family: monospace;
+}
diff --git a/src/run.rs b/src/run.rs
index efd509d..8a5c873 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -111,20 +111,33 @@ impl fmt::Display for RunState {
/// Where did the commit come that CI is run for?
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum Whence {
- Branch { name: String, commit: Oid },
- Patch { patch: Oid, commit: Oid },
+ Branch {
+ name: String,
+ commit: Oid,
+ who: String,
+ },
+ Patch {
+ patch: Oid,
+ commit: Oid,
+ who: String,
+ },
}
impl Whence {
- pub fn branch(name: &str, commit: Oid) -> Self {
+ pub fn branch(name: &str, commit: Oid, who: &str) -> Self {
Self::Branch {
name: name.into(),
commit,
+ who: who.into(),
}
}
- pub fn patch(patch: Oid, commit: Oid) -> Self {
- Self::Patch { patch, commit }
+ pub fn patch(patch: Oid, commit: Oid, who: &str) -> Self {
+ Self::Patch {
+ patch,
+ commit,
+ who: who.into(),
+ }
}
}