| |
pub fn build_trigger_from_ci_event(self) -> Result<Request, MessageError> {
|
| |
fn repository(repo: &RepoId, profile: &Profile) -> Result<Repository, MessageError> {
|
| |
logger::trace2(format!("build trigger: look up repository {repo}"));
|
| - |
let rad_repo = profile.storage.repository(*repo)?;
|
| - |
let project_info = rad_repo.project()?;
|
| + |
let rad_repo = match profile.storage.repository(*repo) {
|
| + |
Err(err) => {
|
| + |
logger::trace2(format!("build trigger: repo lookup result {err:?}"));
|
| + |
return Err(err)?;
|
| + |
}
|
| + |
Ok(rad_repo) => rad_repo,
|
| + |
};
|
| + |
|
| + |
logger::trace("build trigger: look up project");
|
| + |
let project_info = match rad_repo.project() {
|
| + |
Err(err) => {
|
| + |
logger::trace2(format!("build trigger: project lookup result {err:?}"));
|
| + |
return Err(err)?;
|
| + |
}
|
| + |
Ok(x) => x,
|
| + |
};
|
| + |
|
| |
Ok(Repository {
|
| |
id: *repo,
|
| |
name: project_info.name().to_string(),
|
| |
profile: &Profile,
|
| |
) -> Result<EventCommonFields, MessageError> {
|
| |
logger::trace2(format!("build trigger: create common fields for {repo}"));
|
| + |
logger::trace("build trigger: look up repository");
|
| + |
let repository = match repository(repo, profile) {
|
| + |
Err(err) => {
|
| + |
logger::trace2(format!("build trigger: project lookup result {err:?}"));
|
| + |
return Err(err)?;
|
| + |
}
|
| + |
Ok(x) => x,
|
| + |
};
|
| |
Ok(EventCommonFields {
|
| |
version: PROTOCOL_VERSION,
|
| |
event_type,
|
| - |
repository: repository(repo, profile)?,
|
| + |
repository,
|
| |
})
|
| |
}
|
| |
|
| |
fn author(node: &NodeId, profile: &Profile) -> Result<Author, MessageError> {
|
| |
logger::trace2(format!("build trigger: look up author {node}"));
|
| |
let did = Did::from(*node);
|
| - |
did_to_author(profile, &did)
|
| + |
let x = did_to_author(profile, &did);
|
| + |
logger::trace2(format!("build trigger: author lookup result {x:?}"));
|
| + |
x
|
| |
}
|
| |
|
| |
fn commits(
|
| |
base: Oid,
|
| |
) -> Result<Vec<Oid>, radicle_surf::Error> {
|
| |
logger::trace2(format!("build trigger: look commits {git_repo:?}"));
|
| - |
git_repo
|
| + |
let x = git_repo
|
| |
.history(tip)?
|
| |
.take_while(|c| if let Ok(c) = c { c.id != base } else { false })
|
| |
.map(|r| r.map(|c| c.id))
|
| - |
.collect::<Result<Vec<Oid>, _>>()
|
| + |
.collect::<Result<Vec<Oid>, _>>();
|
| + |
logger::trace2(format!("build trigger: revision lookup result {x:?}"));
|
| + |
x
|
| |
}
|
| |
|
| |
fn patch_cob(
|
| |
patch_id: &PatchId,
|
| |
) -> Result<radicle::cob::patch::Patch, MessageError> {
|
| |
logger::trace2(format!("build trigger: look patch cob {patch_id}"));
|
| - |
patch::Patches::open(rad_repo)?
|
| - |
.get(patch_id)?
|
| - |
.ok_or(MessageError::PatchCob(*patch_id))
|
| + |
let x = match patch::Patches::open(rad_repo) {
|
| + |
Err(err) => {
|
| + |
logger::trace2(format!("patch repo open => {err:?}"));
|
| + |
return Err(err)?;
|
| + |
}
|
| + |
Ok(x) => x,
|
| + |
};
|
| + |
|
| + |
let x = match x.get(patch_id) {
|
| + |
Err(err) => {
|
| + |
logger::trace2(format!("get patch => {err:?}"));
|
| + |
return Err(err)?;
|
| + |
}
|
| + |
Ok(x) => x,
|
| + |
};
|
| + |
|
| + |
let x = match x {
|
| + |
None => {
|
| + |
logger::trace("did not find patch COB from repository");
|
| + |
return Err(MessageError::PatchCob(*patch_id));
|
| + |
}
|
| + |
Some(x) => x,
|
| + |
};
|
| + |
|
| + |
logger::trace2(format!("build trigger: patch cob lookup result {x:?}"));
|
| + |
Ok(x)
|
| |
}
|
| |
|
| |
fn revisions(
|
| |
patch_id: &PatchId,
|
| |
author: &Author,
|
| |
) -> Result<Oid, MessageError> {
|
| - |
logger::trace2(format!("build trigger: look patch base {patch_id}"));
|
| + |
logger::trace2(format!(
|
| + |
"build trigger: look base commit for patch {patch_id}"
|
| + |
));
|
| |
let author_pk = radicle::crypto::PublicKey::from(author.id);
|
| - |
let (_id, revision) = patch_cob
|
| - |
.latest_by(&author_pk)
|
| - |
.ok_or(MessageError::LatestPatchRevision(*patch_id))?;
|
| - |
Ok(*revision.base())
|
| + |
let (_id, revision) = match patch_cob.latest_by(&author_pk) {
|
| + |
None => {
|
| + |
logger::trace("build trigger: patch base lookup failed: nothing found");
|
| + |
return Err(MessageError::LatestPatchRevision(*patch_id));
|
| + |
}
|
| + |
Some(x) => x,
|
| + |
};
|
| + |
let base = *revision.base();
|
| + |
logger::trace2(format!("patch base commit is {base}"));
|
| + |
Ok(base)
|
| |
}
|
| |
|
| |
let profile = self.profile.ok_or(MessageError::NoProfile)?;
|