From f38697e2d9af3f12dd2df41992a6b7ccffebb2e2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 18 Jun 2024 19:44:19 +0300 Subject: [PATCH] refactor: move creation of PushEvent to its own function This is clearer for me. Signed-off-by: Lars Wirzenius --- src/msg.rs | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/msg.rs b/src/msg.rs index 742a80d1..9950f13a 100644 --- a/src/msg.rs +++ b/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 = 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::, _>>()?; - 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 { + let push_commits: Vec = repo + .history(after)? + .take_while(|c| if let Ok(c) = c { c.id != before } else { false }) + .map(|r| r.map(|c| c.id)) + .collect::, _>>()?; + Ok(PushEvent { + pusher, + before, + after, + branch: push_branch(branch), + commits: push_commits, + }) + } } /// A request message sent by the broker to its adapter child process.