Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
refactor: move creation of PushEvent to its own function
Lars Wirzenius committed 1 year ago
commit f38697e2d9af3f12dd2df41992a6b7ccffebb2e2
parent d84eccdcb6f799757120ad3da4c790fe9674f0f2
1 file changed +24 -18
modified src/msg.rs
@@ -227,24 +227,8 @@ impl<'a> RequestBuilder<'a> {
                ParsedRef::Push(_branch) => {
                    event_type = EventType::Push;
                    let before_oid: Oid = old.unwrap_or(*oid);
-
                    let push_commits: Vec<Oid> = repo
-
                        .history(oid)?
-
                        .take_while(|c| {
-
                            if let Ok(c) = c {
-
                                c.id != before_oid
-
                            } else {
-
                                false
-
                            }
-
                        })
-
                        .map(|r| r.map(|c| c.id))
-
                        .collect::<Result<Vec<Oid>, _>>()?;
-
                    push_info = Some(PushEvent {
-
                        pusher: author,
-
                        before: before_oid,
-
                        after: *oid,
-
                        branch: push_branch(name),
-
                        commits: push_commits,
-
                    });
+
                    push_info =
+
                        Some(self.build_trigger_from_push(repo, author, name, before_oid, *oid)?);
                    patch_info = None;
                }
            }
@@ -263,6 +247,28 @@ impl<'a> RequestBuilder<'a> {
            Err(MessageError::NoEventHandler)
        }
    }
+

+
    fn build_trigger_from_push(
+
        &self,
+
        repo: radicle_surf::Repository,
+
        pusher: Author,
+
        branch: &str,
+
        before: Oid,
+
        after: Oid,
+
    ) -> Result<PushEvent, MessageError> {
+
        let push_commits: Vec<Oid> = repo
+
            .history(after)?
+
            .take_while(|c| if let Ok(c) = c { c.id != before } else { false })
+
            .map(|r| r.map(|c| c.id))
+
            .collect::<Result<Vec<Oid>, _>>()?;
+
        Ok(PushEvent {
+
            pusher,
+
            before,
+
            after,
+
            branch: push_branch(branch),
+
            commits: push_commits,
+
        })
+
    }
}

/// A request message sent by the broker to its adapter child process.