radicle: Allow editing issue description

Enable editing an Issue's description, returning an error if its not
available.
This commit is contained in:
Slack Coder 2023-05-05 13:03:21 -05:00 committed by Alexis Sellier
parent dc709da33f
commit 39239fea51
No known key found for this signature in database
2 changed files with 51 additions and 1 deletions

View File

@ -34,6 +34,8 @@ pub type IssueId = ObjectId;
pub enum Error {
#[error("apply failed")]
Apply,
#[error("description missing")]
DescriptionMissing,
#[error("thread apply failed: {0}")]
Thread(#[from] thread::OpError),
#[error("store: {0}")]
@ -247,6 +249,16 @@ impl store::Transaction<Issue> {
self.push(Action::Assign { add, remove })
}
/// Edit an issue comment.
pub fn edit_comment(&mut self, id: CommentId, body: impl ToString) -> Result<(), store::Error> {
self.push(Action::Thread {
action: thread::Action::Edit {
id,
body: body.to_string(),
},
})
}
/// Set the issue title.
pub fn edit(&mut self, title: impl ToString) -> Result<(), store::Error> {
self.push(Action::Edit {
@ -335,6 +347,21 @@ impl<'a, 'g> IssueMut<'a, 'g> {
self.transaction("Edit", signer, |tx| tx.edit(title))
}
/// Set the issue description.
pub fn edit_description<G: Signer>(
&mut self,
description: impl ToString,
signer: &G,
) -> Result<EntryId, Error> {
let Some((id, _)) = self.thread.comments().next() else {
return Err(Error::DescriptionMissing);
};
let id = *id;
self.transaction("Edit description", signer, |tx| {
tx.edit_comment(id, description)
})
}
/// Lifecycle an issue.
pub fn lifecycle<G: Signer>(&mut self, state: State, signer: &G) -> Result<EntryId, Error> {
self.transaction("Lifecycle", signer, |tx| tx.lifecycle(state))
@ -734,7 +761,7 @@ mod test {
}
#[test]
fn test_issue_edit_title() {
fn test_issue_edit() {
let tmp = tempfile::tempdir().unwrap();
let test::setup::Context {
signer, project, ..
@ -753,6 +780,28 @@ mod test {
assert_eq!(r, "Sorry typo");
}
#[test]
fn test_issue_edit_description() {
let tmp = tempfile::tempdir().unwrap();
let test::setup::Context {
signer, project, ..
} = test::setup::Context::new(&tmp);
let mut issues = Issues::open(&project).unwrap();
let mut issue = issues
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
.unwrap();
issue
.edit_description("Bob Loblaw law blog", &signer)
.unwrap();
let id = issue.id;
let issue = issues.get(&id).unwrap().unwrap();
let r = issue.description().unwrap();
assert_eq!(r, "Bob Loblaw law blog");
}
#[test]
fn test_issue_react() {
let tmp = tempfile::tempdir().unwrap();

View File

@ -172,6 +172,7 @@ impl Semilattice for Patch {
self.target.merge(other.target);
self.tags.merge(other.tags);
self.revisions.merge(other.revisions);
self.timeline.merge(other.timeline);
}
}