Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
fix: show branch name in push events in HTML reports
Merged liw opened 1 year ago

We used to parse the ref name to find out the branch name, when creating a trigger message. The CI events now do that for us. This meant that parsing the branch name failed, and resulted in the empty string.

Fix this by using already-parsed branch name from the CI event instead of trying to parse it again.

Signed-off-by: Lars Wirzenius liw@liw.fi

2 files changed +6 -47 70f1ba7d 67c215c9
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()
-
        );
-
    }
-
}