Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat(src/msg.rs): add helpers to get repo, commit from Request
Lars Wirzenius committed 2 years ago
commit 1321c25f296ccf6ef80c7eeb1136d9bbd786af86
parent 84051a2f1dc0b90ca6e391d6e47ab6ee25734b5b
1 file changed +31 -0
modified src/msg.rs
@@ -111,6 +111,37 @@ pub enum Request {
}

impl Request {
+
    /// Repository that the event concerns.
+
    pub fn repo(&self) -> RepoId {
+
        match self {
+
            Self::Trigger {
+
                common,
+
                push: _,
+
                patch: _,
+
            } => common.repository.id,
+
        }
+
    }
+

+
    /// Return the commit the event concerns. In other words, the
+
    /// commit that CI should run against.
+
    pub fn commit(&self) -> Oid {
+
        match self {
+
            Self::Trigger {
+
                common: _,
+
                push,
+
                patch,
+
            } => {
+
                if let Some(push) = push {
+
                    *push.commits.last().unwrap()
+
                } else if let Some(patch) = patch {
+
                    *patch.patch.commits.last().unwrap()
+
                } else {
+
                    panic!("neither push not panic: {self:#?}");
+
                }
+
            }
+
        }
+
    }
+

    /// Create a request event to trigger a run.
    pub fn trigger(profile: &Profile, event: &BrokerEvent) -> Result<Self, MessageError> {
        let BrokerEvent::RefChanged {