cob: Add `patch::Action::EditRevision`

To be able to change the description of a patch revision, without the
need to create a new revision.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez 2023-03-30 10:39:09 +02:00 committed by Alexis Sellier
parent fa15ca59f1
commit c9aaaec2ee
No known key found for this signature in database
2 changed files with 43 additions and 0 deletions

View File

@ -626,6 +626,12 @@ async fn patch_update_handler(
} => {
patch.edit(title, description, target, &signer)?;
}
patch::Action::EditRevision {
revision,
description,
} => {
patch.edit_revision(revision, description, &signer)?;
}
patch::Action::Tag { add, remove } => {
patch.tag(add, remove, &signer)?;
}

View File

@ -80,6 +80,10 @@ pub enum Action {
description: String,
target: MergeTarget,
},
EditRevision {
revision: RevisionId,
description: String,
},
Tag {
add: Vec<Tag>,
remove: Vec<Tag>,
@ -273,6 +277,16 @@ impl store::FromHistory for Patch {
self.tags.remove(tag, op.clock);
}
}
Action::EditRevision {
revision,
description,
} => {
if let Some(Redactable::Present(revision)) = self.revisions.get_mut(&revision) {
revision.description.set(description, op.clock);
} else {
return Err(ApplyError::Missing(revision));
}
}
Action::Revision {
description,
base,
@ -606,6 +620,17 @@ impl store::Transaction<Patch> {
})
}
pub fn edit_revision(
&mut self,
revision: RevisionId,
description: impl ToString,
) -> Result<(), store::Error> {
self.push(Action::EditRevision {
revision,
description: description.to_string(),
})
}
/// Start a patch revision discussion.
pub fn thread<S: ToString>(
&mut self,
@ -744,6 +769,18 @@ impl<'a, 'g> PatchMut<'a, 'g> {
self.transaction("Edit", signer, |tx| tx.edit(title, description, target))
}
/// Edit revision metadata.
pub fn edit_revision<G: Signer>(
&mut self,
revision: RevisionId,
description: String,
signer: &G,
) -> Result<EntryId, Error> {
self.transaction("Edit Revision", signer, |tx| {
tx.edit_revision(revision, description)
})
}
/// Create a thread on a patch revision.
pub fn thread<G: Signer, S: ToString>(
&mut self,