summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichalis Zampetakis <mzampetakis@gmail.com>2024-03-04 09:14:04 +0200
committerLars Wirzenius <liw@liw.fi>2024-03-05 12:55:06 +0200
commit472ca9ba8ae85d01aafa159c4930758a88340b45 (patch)
treeb4f1864e3fdcc15b35f94b7055dae41b026cefec
parentf0cb3d2944812d5d0128221d53cf842fe6da783c (diff)
downloadradicle-ci-broker-472ca9ba8ae85d01aafa159c4930758a88340b45.tar.gz
Adds branch name for push events
-rw-r--r--doc/architecture.md2
-rw-r--r--src/event.rs33
-rw-r--r--src/msg.rs7
3 files changed, 40 insertions, 2 deletions
diff --git a/doc/architecture.md b/doc/architecture.md
index 0c25de4..aae14d9 100644
--- a/doc/architecture.md
+++ b/doc/architecture.md
@@ -113,6 +113,7 @@ An example request that the broker sends looks like this:
},
"before": "<BEFORE_COMMIT>",
"after": "<AFTER_COMMIT>",
+ "branch": "<BRANCH_NAME>"
"commits": [
"<SOME_OTHER_COMMIT_BEING_PUSHED>",
"<AFTER_COMMIT>"
@@ -135,6 +136,7 @@ An example request that the broker sends looks like this:
where:
- `<RID>` is the repository ID, in its `rad:` URN format,
+ - `<BRANCH_NAME>` is the branch name where the push occurred,
- `<AFTER_COMMIT>` is the commit id of the last commit being pushed,
- `<BEFORE_COMMIT>` is the commit id of the **parent** of the first
diff --git a/src/event.rs b/src/event.rs
index 7131a34..6c59f4b 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -370,9 +370,20 @@ pub fn is_patch_ref(name: &str) -> Option<&str> {
None
}
+
+pub fn push_branch(name: &str) -> String {
+ let mut parts = name.split("/refs/heads/");
+ if let Some(suffix) = parts.nth(1) {
+ if parts.next().is_none() {
+ return suffix.to_string();
+ }
+ }
+ return "".to_string()
+}
+
#[cfg(test)]
mod test {
- use super::{is_patch_ref, is_patch_update};
+ use super::{is_patch_ref, is_patch_update, push_branch};
#[test]
fn branch_is_not_patch() {
@@ -423,4 +434,24 @@ mod test {
Some("bbb54a2c9314a528a4fff9d6c2aae874ed098433")
);
}
+
+ #[test]
+ fn get_push_branch() {
+ assert_eq!(
+ push_branch(
+ "refs/namespaces/z6MkuhvCnrcow7vzkyQzkuFixzpTa42iC2Cfa4DA8HRLCmys/refs/heads/branch_name"
+ ),
+ "branch_name".to_string()
+ );
+ }
+
+ #[test]
+ fn get_no_push_branch() {
+ assert_eq!(
+ push_branch(
+ "refs/namespaces/z6MkuhvCnrcow7vzkyQzkuFixzpTa42iC2Cfa4DA8HRLCmys/refs/rad/sigrefs"
+ ),
+ "".to_string()
+ );
+ }
}
diff --git a/src/msg.rs b/src/msg.rs
index 2fdf29f..fa10e57 100644
--- a/src/msg.rs
+++ b/src/msg.rs
@@ -27,7 +27,7 @@ use radicle::{patch, Profile};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
-use crate::event::{is_patch_update, BrokerEvent};
+use crate::event::{is_patch_update, BrokerEvent, push_branch};
/// The type of a run identifier. For maximum generality, this is a
/// string rather than an integer.
@@ -250,6 +250,7 @@ impl Request {
pusher: author,
before: before_oid,
after: *oid,
+ branch: push_branch(name),
commits: push_commits,
});
patch_info = None;
@@ -339,6 +340,9 @@ pub struct PushEvent {
/// FIXME
pub after: Oid,
+ /// The branch where the push occurred.
+ pub branch: String,
+
/// The commits in the change.
pub commits: Vec<Oid>,
}
@@ -649,6 +653,7 @@ pub mod tests {
let push = push.unwrap();
assert_eq!(push.after, cmt);
assert_eq!(push.before, repo_head);
+ assert_eq!(push.branch, "master".replace("$nid", &profile.id().to_string()));
assert_eq!(push.commits, vec![cmt]);
assert_eq!(push.pusher.id, Did::from(profile.id()));