Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Support patch commenting
Slack Coder committed 3 years ago
commit ed9900b5aca79568dfd9fd8a29ef7fa075eace15
parent 2c3e7cc2c90c5999224f596f5b4d4e73a19141bc
3 files changed +62 -10
modified radicle-cli/examples/rad-patch.md
@@ -107,3 +107,9 @@ ok Analyzing remotes...
ok Patch 15141cf1497627e2db54362972dd9533f62d1dcb updated 🌱

```
+

+
And lets leave a quick comment for our team:
+

+
```
+
$ rad comment 15141cf1497627e2db54362972dd9533f62d1dcb --message 'I cannot wait to get back to the 90s!'
+
```
modified radicle-cli/src/commands/comment.rs
@@ -5,6 +5,7 @@ use anyhow::anyhow;

use radicle::cob;
use radicle::cob::issue::Issues;
+
use radicle::cob::patch::Patches;
use radicle::cob::store;
use radicle::prelude::*;
use radicle::storage;
@@ -93,15 +94,28 @@ fn comment(
    }

    let mut issues = Issues::open(*signer.public_key(), repo)?;
-
    let mut issue = issues.get_mut(&options.id).map_err(|e| match e {
-
        store::Error::NotFound(_, _) => anyhow::anyhow!("Could not find issue {}", options.id),
-
        _ => e.into(),
-
    })?;
-
    let (comment_id, _) = issue.comments().next().expect("root comment always exists");
+
    match issues.get_mut(&options.id) {
+
        Ok(mut issue) => {
+
            let (comment_id, _) = issue.comments().next().expect("root comment always exists");
+
            issue.comment(message, *comment_id, &signer)?;
+
            return Ok(());
+
        }
+
        Err(store::Error::NotFound(_, _)) => {}
+
        Err(e) => return Err(e.into()),
+
    }

-
    issue.comment(message, *comment_id, &signer)?;
+
    let mut patches = Patches::open(*signer.public_key(), repo)?;
+
    match patches.get_mut(&options.id) {
+
        Ok(mut patch) => {
+
            let (revision_id, _) = patch.revisions().last().expect("patch has a revision");
+
            patch.comment(*revision_id, message, None, &signer)?;
+
            return Ok(());
+
        }
+
        Err(store::Error::NotFound(_, _)) => {}
+
        Err(e) => return Err(e.into()),
+
    }

-
    Ok(())
+
    anyhow::bail!("Couldn't find issue or patch {}", options.id)
}

pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
modified radicle/src/cob/patch.rs
@@ -573,13 +573,13 @@ impl store::Transaction<Patch> {
        &mut self,
        revision: RevisionId,
        body: S,
-
        reply_to: CommentId,
+
        reply_to: Option<CommentId>,
    ) -> OpId {
        self.push(Action::Thread {
            revision,
            action: thread::Action::Comment {
                body: body.to_string(),
-
                reply_to: Some(reply_to),
+
                reply_to,
            },
        })
    }
@@ -696,7 +696,7 @@ impl<'a, 'g> PatchMut<'a, 'g> {
        &mut self,
        revision: RevisionId,
        body: S,
-
        reply_to: CommentId,
+
        reply_to: Option<CommentId>,
        signer: &G,
    ) -> Result<CommentId, Error> {
        self.transaction("Comment", signer, |tx| tx.comment(revision, body, reply_to))
@@ -1065,6 +1065,38 @@ mod test {
    }

    #[test]
+
    fn test_patch_discussion() {
+
        let tmp = tempfile::tempdir().unwrap();
+
        let (_, signer, project) = test::setup::context(&tmp);
+
        let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
+
        let patch = patches
+
            .create(
+
                "My first patch",
+
                "Blah blah blah.",
+
                MergeTarget::Delegates,
+
                git::Oid::try_from("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap(),
+
                git::Oid::try_from("e2a85016a458cd809c0ecee81f8c99613b0b0945").unwrap(),
+
                &[],
+
                &signer,
+
            )
+
            .unwrap();
+

+
        let id = patch.id;
+
        let mut patch = patches.get_mut(&id).unwrap();
+
        let (revision_id, _) = patch.revisions().last().unwrap();
+
        assert!(
+
            patch
+
                .comment(*revision_id, "patch comment", None, &signer)
+
                .is_ok(),
+
            "can comment on patch"
+
        );
+

+
        let (_, revision) = patch.revisions().last().unwrap();
+
        let (_, comment) = revision.discussion.first().unwrap();
+
        assert_eq!("patch comment", comment.body(), "comment body untouched");
+
    }
+

+
    #[test]
    fn test_patch_merge() {
        let tmp = tempfile::tempdir().unwrap();
        let (_, signer, project) = test::setup::context(&tmp);