| |
match parsed_ref {
|
| |
ParsedRef::Patch(_oid) => {
|
| |
event_type = EventType::Patch;
|
| - |
let patch_id = event.patch_id().ok_or(MessageError::Trigger)?;
|
| - |
let patch = patch::Patches::open(&repository)?
|
| - |
.get(&patch_id.into())?
|
| - |
.ok_or(MessageError::Trigger)?;
|
| + |
patch_info = Some(
|
| + |
self.build_trigger_from_patch(event, repository, &repo, profile, author)?,
|
| + |
);
|
| |
push_info = None;
|
| - |
|
| - |
let revs: Vec<Revision> = patch
|
| - |
.revisions()
|
| - |
.map(|(rid, r)| {
|
| - |
Ok::<Revision, MessageError>(Revision {
|
| - |
id: rid.into(),
|
| - |
author: did_to_author(profile, r.author().id())?,
|
| - |
description: r.description().to_string(),
|
| - |
base: *r.base(),
|
| - |
oid: r.head(),
|
| - |
timestamp: r.timestamp().as_secs(),
|
| - |
})
|
| - |
})
|
| - |
.collect::<Result<Vec<Revision>, MessageError>>()?;
|
| - |
let patch_author_pk = radicle::crypto::PublicKey::from(author.id);
|
| - |
let patch_latest_revision = patch
|
| - |
.latest_by(&patch_author_pk)
|
| - |
.ok_or(MessageError::Trigger)?;
|
| - |
let patch_head = patch_latest_revision.1.head();
|
| - |
let patch_base = patch_latest_revision.1.base();
|
| - |
let patch_commits: Vec<Oid> = repo
|
| - |
.history(patch_head)?
|
| - |
.take_while(|c| {
|
| - |
if let Ok(c) = c {
|
| - |
c.id != *patch_base
|
| - |
} else {
|
| - |
false
|
| - |
}
|
| - |
})
|
| - |
.map(|r| r.map(|c| c.id))
|
| - |
.collect::<Result<Vec<Oid>, _>>()?;
|
| - |
let action = if patch.revisions().count() > 1 {
|
| - |
PatchAction::Updated
|
| - |
} else {
|
| - |
PatchAction::Created
|
| - |
};
|
| - |
patch_info = Some(PatchEvent {
|
| - |
action,
|
| - |
patch: Patch {
|
| - |
id: patch_id,
|
| - |
author,
|
| - |
title: patch.title().to_string(),
|
| - |
state: State {
|
| - |
status: patch.state().to_string(),
|
| - |
conflicts: match patch.state() {
|
| - |
patch::State::Open { conflicts, .. } => conflicts.to_vec(),
|
| - |
_ => vec![],
|
| - |
},
|
| - |
},
|
| - |
before: *patch_base,
|
| - |
after: patch_head,
|
| - |
commits: patch_commits,
|
| - |
target: patch.target().head(&repository)?,
|
| - |
labels: patch.labels().map(|l| l.name().to_string()).collect(),
|
| - |
assignees: patch.assignees().collect(),
|
| - |
revisions: revs,
|
| - |
},
|
| - |
});
|
| |
}
|
| |
ParsedRef::Push(_branch) => {
|
| |
event_type = EventType::Push;
|
| |
}
|
| |
}
|
| |
|
| + |
fn build_trigger_from_patch(
|
| + |
&self,
|
| + |
event: &BrokerEvent,
|
| + |
repository: radicle::storage::git::Repository,
|
| + |
repo: &radicle_surf::Repository,
|
| + |
profile: &Profile,
|
| + |
author: Author,
|
| + |
) -> Result<PatchEvent, MessageError> {
|
| + |
let patch_id = event.patch_id().ok_or(MessageError::Trigger)?;
|
| + |
let patch = patch::Patches::open(&repository)?
|
| + |
.get(&patch_id.into())?
|
| + |
.ok_or(MessageError::Trigger)?;
|
| + |
|
| + |
let revs: Vec<Revision> = patch
|
| + |
.revisions()
|
| + |
.map(|(rid, r)| {
|
| + |
Ok::<Revision, MessageError>(Revision {
|
| + |
id: rid.into(),
|
| + |
author: did_to_author(profile, r.author().id())?,
|
| + |
description: r.description().to_string(),
|
| + |
base: *r.base(),
|
| + |
oid: r.head(),
|
| + |
timestamp: r.timestamp().as_secs(),
|
| + |
})
|
| + |
})
|
| + |
.collect::<Result<Vec<Revision>, MessageError>>()?;
|
| + |
let patch_author_pk = radicle::crypto::PublicKey::from(author.id);
|
| + |
let patch_latest_revision = patch
|
| + |
.latest_by(&patch_author_pk)
|
| + |
.ok_or(MessageError::Trigger)?;
|
| + |
let patch_head = patch_latest_revision.1.head();
|
| + |
let patch_base = patch_latest_revision.1.base();
|
| + |
let patch_commits: Vec<Oid> = repo
|
| + |
.history(patch_head)?
|
| + |
.take_while(|c| {
|
| + |
if let Ok(c) = c {
|
| + |
c.id != *patch_base
|
| + |
} else {
|
| + |
false
|
| + |
}
|
| + |
})
|
| + |
.map(|r| r.map(|c| c.id))
|
| + |
.collect::<Result<Vec<Oid>, _>>()?;
|
| + |
let action = if patch.revisions().count() > 1 {
|
| + |
PatchAction::Updated
|
| + |
} else {
|
| + |
PatchAction::Created
|
| + |
};
|
| + |
Ok(PatchEvent {
|
| + |
action,
|
| + |
patch: Patch {
|
| + |
id: patch_id,
|
| + |
author,
|
| + |
title: patch.title().to_string(),
|
| + |
state: State {
|
| + |
status: patch.state().to_string(),
|
| + |
conflicts: match patch.state() {
|
| + |
patch::State::Open { conflicts, .. } => conflicts.to_vec(),
|
| + |
_ => vec![],
|
| + |
},
|
| + |
},
|
| + |
before: *patch_base,
|
| + |
after: patch_head,
|
| + |
commits: patch_commits,
|
| + |
target: patch.target().head(&repository)?,
|
| + |
labels: patch.labels().map(|l| l.name().to_string()).collect(),
|
| + |
assignees: patch.assignees().collect(),
|
| + |
revisions: revs,
|
| + |
},
|
| + |
})
|
| + |
}
|
| + |
|
| |
fn build_trigger_from_push(
|
| |
&self,
|
| |
repo: radicle_surf::Repository,
|