Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: show branch name in push events in HTML reports
Lars Wirzenius committed 1 year ago
commit 67c215c9d85109e7787d74511d11bd806b3f83e7
parent 70f1ba7de5950c8e544fc35e49a7f1123c34d96f
2 files changed +6 -47
modified src/broker.rs
@@ -86,12 +86,12 @@ impl Broker {
                        pusher,
                        before: _,
                        after,
-
                        branch: _,
+
                        branch,
                        commits: _,
                    }) = push
                    {
                        let who = pusher.to_string();
-
                        Whence::branch("push-event-has-no-branch-name", *after, Some(who.as_str()))
+
                        Whence::branch(branch, *after, Some(who.as_str()))
                    } else if let Some(PatchEvent { action: _, patch }) = patch {
                        let revision = patch
                            .revisions
modified src/msg.rs
@@ -161,7 +161,7 @@ impl<'a> RequestBuilder<'a> {
                    pusher,
                    before: *tip, // Branch created: we only use the tip
                    after: *tip,
-
                    branch: push_branch(branch),
+
                    branch: branch.as_str().to_string(),
                    commits: vec![*tip], // Branch created, only use tip.
                };
                Ok(Request::Trigger {
@@ -217,7 +217,7 @@ impl<'a> RequestBuilder<'a> {
                    pusher,
                    before: *tip, // Branch created: we only use the tip
                    after: *tip,
-
                    branch: push_branch(branch),
+
                    branch: branch.as_str().to_string(),
                    commits,
                };

@@ -945,9 +945,7 @@ pub mod trigger_from_ci_event_tests {
        let ci_event = CiEvent::V1(CiEventV1::BranchCreated {
            from_node: *profile.id(),
            repo: project.id,
-
            branch: RefString::try_from(
-
                "refs/namespaces/$nid/refs/heads/master".replace("$nid", &profile.id().to_string()),
-
            )?,
+
            branch: RefString::try_from("master")?,
            tip: cmt,
        });

@@ -996,9 +994,7 @@ pub mod trigger_from_ci_event_tests {
        let ci_event = CiEvent::V1(CiEventV1::BranchUpdated {
            from_node: *profile.id(),
            repo: project.id,
-
            branch: RefString::try_from(
-
                "refs/namespaces/$nid/refs/heads/master".replace("$nid", &profile.id().to_string()),
-
            )?,
+
            branch: RefString::try_from("master")?,
            old_tip: repo_head,
            tip: cmt,
        });
@@ -1176,40 +1172,3 @@ pub mod trigger_from_ci_event_tests {
        Ok(())
    }
}
-

-
// Parse a Git ref to get the branch it refers to. If it doesn't
-
// return to a branch, return the empty string.
-
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();
-
        }
-
    }
-
    "".to_string()
-
}
-

-
#[cfg(test)]
-
mod test_push_branch {
-
    use super::push_branch;
-

-
    #[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()
-
        );
-
    }
-
}