mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-11-21 10:50:38 +08:00
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:
+24
-18
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user