Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: show reviews on `rad patch list`
Merged fintohaps opened 2 years ago

When running rad patch list, show the set of delegate reviews for each patch, with the following meaning for the symbols:

  • ✔: delegate has accepted the patch
  • ✗: delegate has rejected the patch
  • ●: delegate has not made a verdict on the patch
8 files changed +83 -41 ce1e1f71 14ce5fe7
modified radicle-cli/examples/rad-cob.md
@@ -42,11 +42,11 @@ Patch can be listed.

```
$ rad patch
-
╭─────────────────────────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title                      Author                  Head     +   -   Updated │
-
├─────────────────────────────────────────────────────────────────────────────────────────┤
-
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  3e674d1  +0  -0  now     │
-
╰─────────────────────────────────────────────────────────────────────────────────────────╯
+
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title                      Author                  Reviews  Head     +   -   Updated │
+
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  ●        3e674d1  +0  -0  now     │
+
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```

Both issue and patch COBs can be listed.
modified radicle-cli/examples/rad-merge-via-push.md
@@ -69,12 +69,12 @@ To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkE
```
```
$ rad patch --merged
-
╭────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title          Author         Head     +   -   Updated │
-
├────────────────────────────────────────────────────────────────────┤
-
│ ✔  [ ... ]  Second change  alice   (you)  daf349f  +0  -0  now     │
-
│ ✔  [ ... ]  First change   alice   (you)  20aa5dd  +0  -0  now     │
-
╰────────────────────────────────────────────────────────────────────╯
+
╭─────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title          Author         Reviews  Head     +   -   Updated │
+
├─────────────────────────────────────────────────────────────────────────────┤
+
│ ✔  [ ... ]  Second change  alice   (you)  ●        daf349f  +0  -0  now     │
+
│ ✔  [ ... ]  First change   alice   (you)  ●        20aa5dd  +0  -0  now     │
+
╰─────────────────────────────────────────────────────────────────────────────╯
$ rad patch show 356f73863a8920455ff6e77cd9c805d68910551b
╭────────────────────────────────────────────────────────────────╮
│ Title     Second change                                        │
modified radicle-cli/examples/rad-patch-ahead-behind.md
@@ -45,11 +45,11 @@ To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkE
When listing, we see that it has one addition:
```
$ rad patch list
-
╭────────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title     Author                  Head     +   -   Updated │
-
├────────────────────────────────────────────────────────────────────────┤
-
│ ●  217f050  Add Alan  z6MknSL…StBU8Vi  (you)  5c88a79  +1  -0  now     │
-
╰────────────────────────────────────────────────────────────────────────╯
+
╭─────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title     Author                  Reviews  Head     +   -   Updated │
+
├─────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  217f050  Add Alan  z6MknSL…StBU8Vi  (you)  ●        5c88a79  +1  -0  now     │
+
╰─────────────────────────────────────────────────────────────────────────────────╯
```

When showing the patch, we see that it is `ahead 1, behind 1`, since master has
modified radicle-cli/examples/rad-patch-via-push.md
@@ -96,12 +96,12 @@ And both patches:

```
$ rad patch
-
╭───────────────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title            Author                  Head     +   -   Updated │
-
├───────────────────────────────────────────────────────────────────────────────┤
-
│ ●  6035d2f  Add things #1    z6MknSL…StBU8Vi  (you)  42d894a  +0  -0  now     │
-
│ ●  9580891  Add more things  z6MknSL…StBU8Vi  (you)  8b0ea80  +0  -0  now     │
-
╰───────────────────────────────────────────────────────────────────────────────╯
+
╭────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title            Author                  Reviews  Head     +   -   Updated │
+
├────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  6035d2f  Add things #1    z6MknSL…StBU8Vi  (you)  ●        42d894a  +0  -0  now     │
+
│ ●  9580891  Add more things  z6MknSL…StBU8Vi  (you)  ●        8b0ea80  +0  -0  now     │
+
╰────────────────────────────────────────────────────────────────────────────────────────╯
```

To update our patch, we simply push commits to the upstream branch:
modified radicle-cli/examples/rad-patch.md
@@ -35,11 +35,11 @@ It will now be listed as one of the project's open patches.

```
$ rad patch
-
╭─────────────────────────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title                      Author                  Head     +   -   Updated │
-
├─────────────────────────────────────────────────────────────────────────────────────────┤
-
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  3e674d1  +0  -0  now     │
-
╰─────────────────────────────────────────────────────────────────────────────────────────╯
+
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title                      Author                  Reviews  Head     +   -   Updated │
+
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  ●        3e674d1  +0  -0  now     │
+
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```
```
$ rad patch show aa45913e757cacd46972733bddee5472c78fa32a -p
@@ -75,11 +75,11 @@ We can also list only patches that we've authored.

```
$ rad patch list --authored
-
╭─────────────────────────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title                      Author                  Head     +   -   Updated │
-
├─────────────────────────────────────────────────────────────────────────────────────────┤
-
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  3e674d1  +0  -0  now     │
-
╰─────────────────────────────────────────────────────────────────────────────────────────╯
+
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title                      Author                  Reviews  Head     +   -   Updated │
+
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  ●        3e674d1  +0  -0  now     │
+
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```

We can also see that it set an upstream for our patch branch:
@@ -181,6 +181,12 @@ $ rad patch show aa45913
│ ↑ updated to 6e5a3b7b2ce27b32e7ccc2f0b3f4594897dde638 (27857ec) now │
│   └─ ✓ accepted by z6MknSL…StBU8Vi (you) now                        │
╰─────────────────────────────────────────────────────────────────────╯
+
$ rad patch list
+
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title                      Author                  Reviews  Head     +   -   Updated │
+
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  aa45913  Define power requirements  z6MknSL…StBU8Vi  (you)  ✔        27857ec  +0  -0  now     │
+
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```

If you make a mistake on the patch description, you can always change it!
modified radicle-cli/examples/workflow/4-patching-contributor.md
@@ -35,11 +35,11 @@ It will now be listed as one of the project's open patches.

```
$ rad patch
-
╭────────────────────────────────────────────────────────────────────────────────╮
-
│ ●  ID       Title                      Author         Head     +   -   Updated │
-
├────────────────────────────────────────────────────────────────────────────────┤
-
│ ●  e4934b6  Define power requirements  bob     (you)  3e674d1  +0  -0  now     │
-
╰────────────────────────────────────────────────────────────────────────────────╯
+
╭─────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title                      Author         Reviews  Head     +   -   Updated │
+
├─────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  e4934b6  Define power requirements  bob     (you)  ●        3e674d1  +0  -0  now     │
+
╰─────────────────────────────────────────────────────────────────────────────────────────╯
$ rad patch show e4934b6d9dbe01ce3c7fbb5b77a80d5f1dacdc46
╭────────────────────────────────────────────────────╮
│ Title     Define power requirements                │
modified radicle-cli/src/commands/patch/list.rs
@@ -1,4 +1,4 @@
-
use std::collections::BTreeSet;
+
use std::collections::{BTreeMap, BTreeSet};

use radicle::cob::patch;
use radicle::cob::patch::{Patch, PatchId};
@@ -46,7 +46,7 @@ pub fn run(
        return Ok(());
    }

-
    let mut table = Table::<9, term::Line>::new(TableOptions {
+
    let mut table = Table::<10, term::Line>::new(TableOptions {
        spacing: 2,
        border: Some(term::colors::FAINT),
        ..TableOptions::default()
@@ -58,6 +58,7 @@ pub fn run(
        term::format::bold(String::from("Title")).into(),
        term::format::bold(String::from("Author")).into(),
        term::Line::blank(),
+
        term::format::bold(String::from("Reviews")).into(),
        term::format::bold(String::from("Head")).into(),
        term::format::bold(String::from("+")).into(),
        term::format::bold(String::from("-")).into(),
@@ -98,13 +99,39 @@ pub fn row(
    patch: &Patch,
    repository: &Repository,
    profile: &Profile,
-
) -> anyhow::Result<[term::Line; 9]> {
+
) -> anyhow::Result<[term::Line; 10]> {
    let state = patch.state();
    let (_, revision) = patch.latest();
    let (from, to) = revision.range();
    let stats = common::diff_stats(repository.raw(), &from, &to)?;
    let author = patch.author().id;
    let (alias, did) = Author::new(&author, profile).labels();
+
    let mut delegates = repository
+
        .delegates()?
+
        .into_iter()
+
        .map(|delegate| (*delegate, term::format::patch::verdict(None)))
+
        .collect::<BTreeMap<_, _>>();
+
    for (key, review) in revision.reviews() {
+
        delegates
+
            .entry(*key)
+
            .and_modify(|verdict| *verdict = term::format::patch::verdict(review.verdict()));
+
    }
+
    let n = delegates.len();
+
    let reviews = delegates
+
        .values()
+
        .cloned()
+
        .map(term::Label::from)
+
        // TODO(finto): poor man's intersperse
+
        // https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.intersperse
+
        .enumerate()
+
        .flat_map(|(i, label)| {
+
            if i == n - 1 {
+
                vec![label].into_iter()
+
            } else {
+
                vec![label, term::Label::from(",")].into_iter()
+
            }
+
        })
+
        .collect::<Vec<_>>();

    Ok([
        match state {
@@ -117,6 +144,7 @@ pub fn row(
        term::format::default(patch.title().to_owned()).into(),
        alias.into(),
        did.into(),
+
        reviews.into(),
        term::format::secondary(term::format::oid(revision.head())).into(),
        term::format::positive(format!("+{}", stats.insertions())).into(),
        term::format::negative(format!("-{}", stats.deletions())).into(),
modified radicle-cli/src/terminal/format.rs
@@ -264,7 +264,15 @@ pub mod issue {
/// Patch formatting
pub mod patch {
    use super::*;
-
    use radicle::patch::State;
+
    use radicle::patch::{State, Verdict};
+

+
    pub fn verdict(v: Option<Verdict>) -> term::Paint<String> {
+
        match v {
+
            Some(Verdict::Accept) => term::format::positive("✔".to_string()),
+
            Some(Verdict::Reject) => term::format::negative("✗".to_string()),
+
            None => term::format::secondary("●".to_string()),
+
        }
+
    }

    /// Format patch state.
    pub fn state(s: &State) -> term::Paint<String> {