refactor: move creation of PushEvent to its own function

This is clearer for me.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2024-06-18 20:36:22 +03:00
parent d84eccdcb6
commit f38697e2d9
+24 -18
View File
@@ -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.