From 14ce5fe7b177d57ab33872d90c5a819c5db13bb6 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 8 Mar 2024 12:05:33 +0000 Subject: [PATCH] cli: show reviews on `rad patch list` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-cli/examples/rad-cob.md | 10 +++--- radicle-cli/examples/rad-merge-via-push.md | 12 +++---- .../examples/rad-patch-ahead-behind.md | 10 +++--- radicle-cli/examples/rad-patch-via-push.md | 12 +++---- radicle-cli/examples/rad-patch.md | 26 ++++++++------ .../workflow/4-patching-contributor.md | 10 +++--- radicle-cli/src/commands/patch/list.rs | 34 +++++++++++++++++-- radicle-cli/src/terminal/format.rs | 10 +++++- 8 files changed, 83 insertions(+), 41 deletions(-) diff --git a/radicle-cli/examples/rad-cob.md b/radicle-cli/examples/rad-cob.md index 02ab69a2..38d743d1 100644 --- a/radicle-cli/examples/rad-cob.md +++ b/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. diff --git a/radicle-cli/examples/rad-merge-via-push.md b/radicle-cli/examples/rad-merge-via-push.md index e07fe6d8..c7927229 100644 --- a/radicle-cli/examples/rad-merge-via-push.md +++ b/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 │ diff --git a/radicle-cli/examples/rad-patch-ahead-behind.md b/radicle-cli/examples/rad-patch-ahead-behind.md index d04a66b6..c7abb5b3 100644 --- a/radicle-cli/examples/rad-patch-ahead-behind.md +++ b/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 diff --git a/radicle-cli/examples/rad-patch-via-push.md b/radicle-cli/examples/rad-patch-via-push.md index e00581b6..a9a210d7 100644 --- a/radicle-cli/examples/rad-patch-via-push.md +++ b/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: diff --git a/radicle-cli/examples/rad-patch.md b/radicle-cli/examples/rad-patch.md index 23fa0e44..e48b6ff4 100644 --- a/radicle-cli/examples/rad-patch.md +++ b/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! diff --git a/radicle-cli/examples/workflow/4-patching-contributor.md b/radicle-cli/examples/workflow/4-patching-contributor.md index 4c73853a..626081cd 100644 --- a/radicle-cli/examples/workflow/4-patching-contributor.md +++ b/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 │ diff --git a/radicle-cli/src/commands/patch/list.rs b/radicle-cli/src/commands/patch/list.rs index a96ee5a8..8a89be5c 100644 --- a/radicle-cli/src/commands/patch/list.rs +++ b/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::>(); + 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::space()].into_iter() + } + }) + .collect::>(); 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(), diff --git a/radicle-cli/src/terminal/format.rs b/radicle-cli/src/terminal/format.rs index dc4f16a5..1da4f504 100644 --- a/radicle-cli/src/terminal/format.rs +++ b/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) -> term::Paint { + match v { + Some(Verdict::Accept) => term::format::positive("✔".to_string()), + Some(Verdict::Reject) => term::format::negative("✗".to_string()), + None => term::format::dim("-".to_string()), + } + } /// Format patch state. pub fn state(s: &State) -> term::Paint {