cli: Use `.aliases()` store for patches
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
parent
ff81b1a6ed
commit
37847d4c63
|
|
@ -68,7 +68,7 @@ $ rad patch show -v -p 866f59c
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 5c88a79 Add Alan │
|
│ 5c88a79 Add Alan │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
commit 5c88a79d75f5c2b4cc51ee6f163d2db91ee198d7
|
commit 5c88a79d75f5c2b4cc51ee6f163d2db91ee198d7
|
||||||
|
|
@ -115,7 +115,7 @@ $ rad patch show -v 57cb9b2758518e547de324456ac967fda456c6c1
|
||||||
│ 7f63fcb Add Mel │
|
│ 7f63fcb Add Mel │
|
||||||
│ 5c88a79 Add Alan │
|
│ 5c88a79 Add Alan │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -149,6 +149,6 @@ $ rad patch show -v 395221c5b75fa9bc2de7909d03e69dfd606611c6
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 7f63fcb Add Mel │
|
│ 7f63fcb Add Mel │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ $ rad patch show c639a0f9895a0fdf2ba2d04533290937cb6fd2f7
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 2a46583 Nothing to see here.. │
|
│ 2a46583 Nothing to see here.. │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ $ rad patch show c639a0f9895a0fdf2ba2d04533290937cb6fd2f7
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 2a46583 Nothing to see here.. │
|
│ 2a46583 Nothing to see here.. │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -73,5 +73,5 @@ $ rad patch show c639a0f9895a0fdf2ba2d04533290937cb6fd2f7
|
||||||
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ 2a46583 Nothing to see here.. │
|
│ 2a46583 Nothing to see here.. │
|
||||||
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰─────────────────────────────────────────────────────────────────────────────────────────╯
|
╰─────────────────────────────────────────────────────────────────────────────────────────╯
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ $ rad patch show 51e0d0bc168ccdc541b7b1aeab2eb9e048c2fcdd
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 51b2f0f Not a real change │
|
│ 51b2f0f Not a real change │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ $ rad patch show 51e0d0bc168ccdc541b7b1aeab2eb9e048c2fcdd
|
||||||
│ 4d27214 Rename readme file │
|
│ 4d27214 Rename readme file │
|
||||||
│ 51b2f0f Not a real change │
|
│ 51b2f0f Not a real change │
|
||||||
├──────────────────────────────────────────────────────────────────────────────┤
|
├──────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
│ ↑ updated to c10012c2cb9c0c9bfeba7ef28cae10e4b8db3469 (4d27214) [ ... ] │
|
│ ↑ updated to c10012c2cb9c0c9bfeba7ef28cae10e4b8db3469 (4d27214) [ ... ] │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ $ rad patch show 2647168
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 42d894a Add things │
|
│ 42d894a Add things │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -141,7 +141,7 @@ $ rad patch show b8ab1c9
|
||||||
│ 02bef3f Improve code │
|
│ 02bef3f Improve code │
|
||||||
│ 8b0ea80 Add more things │
|
│ 8b0ea80 Add more things │
|
||||||
├──────────────────────────────────────────────────────────────────────────────┤
|
├──────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
│ ↑ updated to 8767880c31b9e4a04cdb07ad6faa9ce453980399 (02bef3f) [ ... ] │
|
│ ↑ updated to 8767880c31b9e4a04cdb07ad6faa9ce453980399 (02bef3f) [ ... ] │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
@ -217,7 +217,7 @@ $ rad patch show b8ab1c9
|
||||||
│ 9304dbc Amended commit │
|
│ 9304dbc Amended commit │
|
||||||
│ 8b0ea80 Add more things │
|
│ 8b0ea80 Add more things │
|
||||||
├──────────────────────────────────────────────────────────────────────────────┤
|
├──────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
│ ↑ updated to 8767880c31b9e4a04cdb07ad6faa9ce453980399 (02bef3f) [ ... ] │
|
│ ↑ updated to 8767880c31b9e4a04cdb07ad6faa9ce453980399 (02bef3f) [ ... ] │
|
||||||
│ ↑ updated to f24334f8cea7b7a5bcaf3bc6deb1408c9bf507ad (9304dbc) [ ... ] │
|
│ ↑ updated to f24334f8cea7b7a5bcaf3bc6deb1408c9bf507ad (9304dbc) [ ... ] │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ $ rad patch show 077e4bbe9a6e5546f400ef5951768c37a76f13a4 -p
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 3e674d1 Define power requirements │
|
│ 3e674d1 Define power requirements │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
commit 3e674d1a1df90807e934f9ae5da2591dd6848a33
|
commit 3e674d1a1df90807e934f9ae5da2591dd6848a33
|
||||||
|
|
@ -137,9 +137,9 @@ $ rad patch show 077e4bb
|
||||||
│ 27857ec Add README, just for the fun │
|
│ 27857ec Add README, just for the fun │
|
||||||
│ 3e674d1 Define power requirements │
|
│ 3e674d1 Define power requirements │
|
||||||
├──────────────────────────────────────────────────────────────────────────────┤
|
├──────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
│ ↑ updated to 5cdcd2e14411e2bfec7b11bcf4667e2e0fc4d417 (27857ec) [ ... ] │
|
│ ↑ updated to 5cdcd2e14411e2bfec7b11bcf4667e2e0fc4d417 (27857ec) [ ... ] │
|
||||||
│ ✓ accepted by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ✓ accepted by (you) [ ... ] │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -162,8 +162,8 @@ $ rad patch show 077e4bb
|
||||||
│ 27857ec Add README, just for the fun │
|
│ 27857ec Add README, just for the fun │
|
||||||
│ 3e674d1 Define power requirements │
|
│ 3e674d1 Define power requirements │
|
||||||
├──────────────────────────────────────────────────────────────────────────────┤
|
├──────────────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
│ ↑ updated to 5cdcd2e14411e2bfec7b11bcf4667e2e0fc4d417 (27857ec) [ ... ] │
|
│ ↑ updated to 5cdcd2e14411e2bfec7b11bcf4667e2e0fc4d417 (27857ec) [ ... ] │
|
||||||
│ ✓ accepted by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ✓ accepted by (you) [ ... ] │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ $ rad patch show 50e29a111972f3b7d2123c5057de5bdf09bc7b1c
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ 3e674d1 Define power requirements │
|
│ 3e674d1 Define power requirements │
|
||||||
├────────────────────────────────────────────────────────────────────┤
|
├────────────────────────────────────────────────────────────────────┤
|
||||||
│ ● opened by (you) (z6Mkt67…v4N1tRk) [ ... ] │
|
│ ● opened by (you) [ ... ] │
|
||||||
╰────────────────────────────────────────────────────────────────────╯
|
╰────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ $ rad patch show 50e29a1
|
||||||
│ ● opened by bob (z6Mkt67…v4N1tRk) [ ... ] │
|
│ ● opened by bob (z6Mkt67…v4N1tRk) [ ... ] │
|
||||||
│ ↑ updated to 3530243d46a2e7a8e4eac7afcbb17cc7c56b3d29 (27857ec) [ ... ] │
|
│ ↑ updated to 3530243d46a2e7a8e4eac7afcbb17cc7c56b3d29 (27857ec) [ ... ] │
|
||||||
│ ↑ updated to 744c1f0a75b1c42833c9aa32f79cd40443925d66 (f567f69) [ ... ] │
|
│ ↑ updated to 744c1f0a75b1c42833c9aa32f79cd40443925d66 (f567f69) [ ... ] │
|
||||||
│ ✓ merged by (you) (z6MknSL…StBU8Vi) [ ... ] │
|
│ ✓ merged by (you) [ ... ] │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
use radicle::cob::patch;
|
use radicle::cob::patch;
|
||||||
use radicle::cob::patch::{Patch, PatchId, Patches, Verdict};
|
use radicle::cob::patch::{Patch, PatchId, Patches, Verdict};
|
||||||
|
use radicle::node::AliasStore;
|
||||||
use radicle::prelude::*;
|
use radicle::prelude::*;
|
||||||
use radicle::profile::Profile;
|
use radicle::profile::Profile;
|
||||||
use radicle::storage::git::Repository;
|
use radicle::storage::git::Repository;
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
use term::format::Author;
|
||||||
use term::table::{Table, TableOptions};
|
use term::table::{Table, TableOptions};
|
||||||
use term::Element as _;
|
use term::Element as _;
|
||||||
|
|
||||||
|
|
@ -63,13 +65,13 @@ pub fn run(
|
||||||
is_me.then(by_rev_time).then(by_id)
|
is_me.then(by_rev_time).then(by_id)
|
||||||
});
|
});
|
||||||
|
|
||||||
let store = profile.tracking()?;
|
let aliases = profile.aliases()?;
|
||||||
|
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
for (id, patch) in &mut all {
|
for (id, patch) in &mut all {
|
||||||
let author_id = patch.author().id();
|
let author_id = patch.author().id();
|
||||||
let alias = store.node_policy(author_id)?.and_then(|node| node.alias);
|
let alias = aliases.alias(author_id);
|
||||||
match row(&me, alias, id, patch, repository) {
|
match row(profile, alias, id, patch, repository) {
|
||||||
Ok(r) => table.push(r),
|
Ok(r) => table.push(r),
|
||||||
Err(e) => errors.push((patch.title(), id, e.to_string())),
|
Err(e) => errors.push((patch.title(), id, e.to_string())),
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +92,7 @@ pub fn run(
|
||||||
|
|
||||||
/// Patch row.
|
/// Patch row.
|
||||||
pub fn row(
|
pub fn row(
|
||||||
whoami: &PublicKey,
|
profile: &Profile,
|
||||||
alias: Option<String>,
|
alias: Option<String>,
|
||||||
id: &PatchId,
|
id: &PatchId,
|
||||||
patch: &Patch,
|
patch: &Patch,
|
||||||
|
|
@ -101,6 +103,7 @@ pub fn row(
|
||||||
let (from, to) = patch.range(repository)?;
|
let (from, to) = patch.range(repository)?;
|
||||||
let stats = common::diff_stats(repository.raw(), &from, &to)?;
|
let stats = common::diff_stats(repository.raw(), &from, &to)?;
|
||||||
let author = patch.author().id;
|
let author = patch.author().id;
|
||||||
|
let display = Author::new(&author, alias, profile);
|
||||||
|
|
||||||
Ok([
|
Ok([
|
||||||
match state {
|
match state {
|
||||||
|
|
@ -112,13 +115,7 @@ pub fn row(
|
||||||
term::format::tertiary(term::format::cob(id)).into(),
|
term::format::tertiary(term::format::cob(id)).into(),
|
||||||
term::format::default(patch.title().to_owned()).into(),
|
term::format::default(patch.title().to_owned()).into(),
|
||||||
term::format::did(&author).dim().into(),
|
term::format::did(&author).dim().into(),
|
||||||
if author.as_key() == whoami {
|
display.alias(),
|
||||||
term::format::primary("(you)".to_owned()).into()
|
|
||||||
} else if let Some(alias) = alias {
|
|
||||||
term::format::primary(alias).into()
|
|
||||||
} else {
|
|
||||||
term::format::default(String::new()).into()
|
|
||||||
},
|
|
||||||
term::format::secondary(term::format::oid(revision.head())).into(),
|
term::format::secondary(term::format::oid(revision.head())).into(),
|
||||||
term::format::positive(format!("+{}", stats.insertions())).into(),
|
term::format::positive(format!("+{}", stats.insertions())).into(),
|
||||||
term::format::negative(format!("-{}", stats.deletions())).into(),
|
term::format::negative(format!("-{}", stats.deletions())).into(),
|
||||||
|
|
@ -135,33 +132,14 @@ pub fn timeline(
|
||||||
patch: &Patch,
|
patch: &Patch,
|
||||||
repository: &Repository,
|
repository: &Repository,
|
||||||
) -> anyhow::Result<Vec<term::Line>> {
|
) -> anyhow::Result<Vec<term::Line>> {
|
||||||
let whoami = profile.id();
|
let aliases = profile.aliases()?;
|
||||||
let store = profile.tracking()?;
|
let alias = aliases.alias(patch.author().id());
|
||||||
let alias = if patch.author().id().as_key() == whoami {
|
let open = term::Line::spaced([
|
||||||
Some("(you)".to_string())
|
|
||||||
} else {
|
|
||||||
store
|
|
||||||
.node_policy(patch.author().id())?
|
|
||||||
.and_then(|node| node.alias)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut open = term::Line::spaced([
|
|
||||||
term::format::positive("●").into(),
|
term::format::positive("●").into(),
|
||||||
term::format::default("opened by").into(),
|
term::format::default("opened by").into(),
|
||||||
]);
|
])
|
||||||
|
.space()
|
||||||
open.push(term::Label::space());
|
.extend(Author::new(patch.author().id(), alias, profile));
|
||||||
|
|
||||||
if let Some(ref alias) = alias {
|
|
||||||
open.push(term::format::primary(alias));
|
|
||||||
open.push(term::Label::space());
|
|
||||||
open.push(term::format::tertiary(format!(
|
|
||||||
"({})",
|
|
||||||
term::format::node(patch.author().id())
|
|
||||||
)));
|
|
||||||
} else {
|
|
||||||
open.push(term::format::tertiary(patch.author().id()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut timeline = vec![(patch.timestamp(), open)];
|
let mut timeline = vec![(patch.timestamp(), open)];
|
||||||
|
|
||||||
|
|
@ -187,37 +165,16 @@ pub fn timeline(
|
||||||
|
|
||||||
for (nid, merge) in patch.merges().filter(|(_, m)| m.revision == *revision_id) {
|
for (nid, merge) in patch.merges().filter(|(_, m)| m.revision == *revision_id) {
|
||||||
let peer = repository.remote(nid)?;
|
let peer = repository.remote(nid)?;
|
||||||
let alias = if peer.id == *whoami {
|
let alias = aliases.alias(&peer.id);
|
||||||
Some("(you)".to_string())
|
let line = term::Line::spaced([
|
||||||
} else {
|
term::format::primary("✓").bold().into(),
|
||||||
store.node_policy(&peer.id)?.and_then(|node| node.alias)
|
term::format::default("merged").into(),
|
||||||
};
|
term::format::default("by").into(),
|
||||||
|
])
|
||||||
|
.space()
|
||||||
|
.extend(Author::new(&peer.id, alias, profile));
|
||||||
|
|
||||||
timeline.push((
|
timeline.push((merge.timestamp, line));
|
||||||
merge.timestamp,
|
|
||||||
term::Line::spaced(
|
|
||||||
[
|
|
||||||
term::format::primary("✓").bold().into(),
|
|
||||||
term::format::default("merged").into(),
|
|
||||||
term::format::default("by").into(),
|
|
||||||
if let Some(ref alias) = alias {
|
|
||||||
term::format::primary(alias).into()
|
|
||||||
} else {
|
|
||||||
term::format::default(String::new()).into()
|
|
||||||
},
|
|
||||||
if alias.is_some() {
|
|
||||||
term::format::tertiary(format!(
|
|
||||||
"({})",
|
|
||||||
term::format::node(&Did::from(peer.id))
|
|
||||||
))
|
|
||||||
.into()
|
|
||||||
} else {
|
|
||||||
term::format::tertiary(Did::from(peer.id)).into()
|
|
||||||
},
|
|
||||||
]
|
|
||||||
.into_iter(),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
for (reviewer, review) in revision.reviews() {
|
for (reviewer, review) in revision.reviews() {
|
||||||
let verdict = review.verdict();
|
let verdict = review.verdict();
|
||||||
|
|
@ -232,37 +189,16 @@ pub fn timeline(
|
||||||
None => term::format::default("reviewed"),
|
None => term::format::default("reviewed"),
|
||||||
};
|
};
|
||||||
let peer = repository.remote(reviewer)?;
|
let peer = repository.remote(reviewer)?;
|
||||||
let alias = if peer.id == *whoami {
|
let alias = aliases.alias(&peer.id);
|
||||||
Some("(you)".to_string())
|
let line = term::Line::spaced([
|
||||||
} else {
|
verdict_symbol.into(),
|
||||||
store.node_policy(&peer.id)?.and_then(|node| node.alias)
|
verdict_verb.into(),
|
||||||
};
|
term::format::default("by").into(),
|
||||||
|
])
|
||||||
|
.space()
|
||||||
|
.extend(Author::new(&peer.id, alias, profile));
|
||||||
|
|
||||||
timeline.push((
|
timeline.push((review.timestamp(), line));
|
||||||
review.timestamp(),
|
|
||||||
term::Line::spaced(
|
|
||||||
[
|
|
||||||
verdict_symbol.into(),
|
|
||||||
verdict_verb.into(),
|
|
||||||
term::format::default("by").into(),
|
|
||||||
if let Some(ref alias) = alias {
|
|
||||||
term::format::primary(alias).into()
|
|
||||||
} else {
|
|
||||||
term::format::default(String::new()).into()
|
|
||||||
},
|
|
||||||
if alias.is_some() {
|
|
||||||
term::format::tertiary(format!(
|
|
||||||
"({})",
|
|
||||||
term::format::node(&Did::from(reviewer))
|
|
||||||
))
|
|
||||||
.into()
|
|
||||||
} else {
|
|
||||||
term::format::tertiary(Did::from(reviewer)).into()
|
|
||||||
},
|
|
||||||
]
|
|
||||||
.into_iter(),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timeline.sort_by_key(|(t, _)| *t);
|
timeline.sort_by_key(|(t, _)| *t);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use radicle::cob::{ObjectId, Timestamp};
|
||||||
use radicle::node::{AliasStore, NodeId};
|
use radicle::node::{AliasStore, NodeId};
|
||||||
use radicle::prelude::Did;
|
use radicle::prelude::Did;
|
||||||
use radicle::profile::Profile;
|
use radicle::profile::Profile;
|
||||||
|
use radicle_term::element::Line;
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
|
||||||
|
|
@ -138,6 +139,92 @@ impl<'a> fmt::Display for Identity<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This enum renders (nid, alias) in terminal depending on user variant.
|
||||||
|
pub enum Author<'a> {
|
||||||
|
Author {
|
||||||
|
nid: &'a NodeId,
|
||||||
|
alias: Option<String>,
|
||||||
|
},
|
||||||
|
Me {
|
||||||
|
alias: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Author<'a> {
|
||||||
|
pub fn new(nid: &'a NodeId, alias: Option<String>, me: &Profile) -> Author<'a> {
|
||||||
|
if nid == me.id() {
|
||||||
|
Self::Me { alias }
|
||||||
|
} else {
|
||||||
|
Self::Author { nid, alias }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Author: `<alias>` || ``
|
||||||
|
/// Me : `<alias> (you)` || `(you)`
|
||||||
|
pub fn alias(&self) -> Line {
|
||||||
|
match self {
|
||||||
|
Self::Me { alias } => {
|
||||||
|
if let Some(alias) = alias {
|
||||||
|
term::Line::spaced([
|
||||||
|
term::format::primary(alias).into(),
|
||||||
|
term::format::primary("(you)").dim().into(),
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
term::format::primary("(you)").into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Author { alias, .. } => {
|
||||||
|
if let Some(alias) = alias {
|
||||||
|
term::format::primary(alias).into()
|
||||||
|
} else {
|
||||||
|
term::format::default(String::new()).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> IntoIterator for Author<'a> {
|
||||||
|
type Item = term::Label;
|
||||||
|
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||||
|
|
||||||
|
/// Author : `<alias> (<compact-nid>)` || `<nid>`
|
||||||
|
/// Me : `<alias> (you)` || `(you)`
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
let mut line = Vec::new();
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Self::Me { alias } => {
|
||||||
|
if let Some(alias) = alias {
|
||||||
|
line.push(term::format::primary(alias).into());
|
||||||
|
line.push(term::Label::space());
|
||||||
|
line.push(term::format::primary("(you)").dim().into());
|
||||||
|
} else {
|
||||||
|
line.push(term::format::primary("(you)").into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Author { nid, alias } => {
|
||||||
|
if let Some(alias) = alias {
|
||||||
|
line.push(term::format::primary(alias).into());
|
||||||
|
line.push(term::Label::space());
|
||||||
|
line.push(
|
||||||
|
term::format::tertiary(term::format::parens(
|
||||||
|
term::format::node(nid).into(),
|
||||||
|
))
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
line.push(term::format::tertiary(nid).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,11 @@ use radicle::crypto::{KeyPair, Seed, Signer};
|
||||||
use radicle::git;
|
use radicle::git;
|
||||||
use radicle::git::refname;
|
use radicle::git::refname;
|
||||||
use radicle::identity::Id;
|
use radicle::identity::Id;
|
||||||
|
use radicle::node::address::Book;
|
||||||
use radicle::node::routing::Store;
|
use radicle::node::routing::Store;
|
||||||
use radicle::node::tracking::store as TrackingStore;
|
use radicle::node::tracking::store as TrackingStore;
|
||||||
use radicle::node::Handle as _;
|
use radicle::node::Handle as _;
|
||||||
use radicle::node::TRACKING_DB_FILE;
|
use radicle::node::{ADDRESS_DB_FILE, TRACKING_DB_FILE};
|
||||||
use radicle::profile::Home;
|
use radicle::profile::Home;
|
||||||
use radicle::profile::Profile;
|
use radicle::profile::Profile;
|
||||||
use radicle::rad;
|
use radicle::rad;
|
||||||
|
|
@ -78,6 +79,8 @@ impl Environment {
|
||||||
let signer = MemorySigner::load(&profile.keystore, "radicle".to_owned().into()).unwrap();
|
let signer = MemorySigner::load(&profile.keystore, "radicle".to_owned().into()).unwrap();
|
||||||
let tracking_db = profile.home.node().join(TRACKING_DB_FILE);
|
let tracking_db = profile.home.node().join(TRACKING_DB_FILE);
|
||||||
TrackingStore::Config::open(tracking_db).unwrap();
|
TrackingStore::Config::open(tracking_db).unwrap();
|
||||||
|
let addresses_db = profile.home.node().join(ADDRESS_DB_FILE);
|
||||||
|
Book::open(addresses_db).unwrap();
|
||||||
|
|
||||||
Node {
|
Node {
|
||||||
id: *profile.id(),
|
id: *profile.id(),
|
||||||
|
|
@ -96,6 +99,8 @@ impl Environment {
|
||||||
let keypair = KeyPair::from_seed(Seed::from([!(self.users as u8); 32]));
|
let keypair = KeyPair::from_seed(Seed::from([!(self.users as u8); 32]));
|
||||||
let tracking_db = home.node().join(TRACKING_DB_FILE);
|
let tracking_db = home.node().join(TRACKING_DB_FILE);
|
||||||
TrackingStore::Config::open(tracking_db).unwrap();
|
TrackingStore::Config::open(tracking_db).unwrap();
|
||||||
|
let addresses_db = home.node().join(ADDRESS_DB_FILE);
|
||||||
|
Book::open(addresses_db).unwrap();
|
||||||
|
|
||||||
transport::local::register(storage.clone());
|
transport::local::register(storage.clone());
|
||||||
keystore
|
keystore
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue