Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
Adds branch name for push events
Merged did:key:z6MkkpTP...arsB opened 2 years ago
3 files changed +40 -2 3c2c2c24 3c2c2c24
modified 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 

modified 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()
+
        );
+
    }
}
modified src/msg.rs
@@ -26,7 +26,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.
@@ -243,6 +243,7 @@ impl Request {
                pusher: author,
                before: before_oid,
                after: *oid,
+
                branch: push_branch(name),
                commits: push_commits,
            });
            patch_info = None;
@@ -332,6 +333,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>,
}
@@ -642,6 +646,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()));