cli: Use `.aliases()` store for issues

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex 2023-06-28 13:25:16 +00:00 committed by Alexis Sellier
parent 37847d4c63
commit 1459e4a57f
No known key found for this signature in database
1 changed files with 32 additions and 34 deletions

View File

@ -9,7 +9,7 @@ use radicle::cob::common::{Reaction, Tag};
use radicle::cob::issue; use radicle::cob::issue;
use radicle::cob::issue::{CloseReason, Issues, State}; use radicle::cob::issue::{CloseReason, Issues, State};
use radicle::crypto::Signer; use radicle::crypto::Signer;
use radicle::node::Handle; use radicle::node::{AliasStore, Handle};
use radicle::prelude::Did; use radicle::prelude::Did;
use radicle::profile; use radicle::profile;
use radicle::storage; use radicle::storage;
@ -21,6 +21,7 @@ use radicle_term::{Paint, Table, VStack};
use crate::git::Rev; use crate::git::Rev;
use crate::terminal as term; use crate::terminal as term;
use crate::terminal::args::{string, Args, Error, Help}; use crate::terminal::args::{string, Args, Error, Help};
use crate::terminal::format::Author;
use crate::terminal::Element; use crate::terminal::Element;
pub const HELP: Help = Help { pub const HELP: Help = Help {
@ -349,8 +350,6 @@ fn list(
state: &Option<State>, state: &Option<State>,
profile: &profile::Profile, profile: &profile::Profile,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let me = *profile.id();
if issues.is_empty()? { if issues.is_empty()? {
term::print(term::format::italic("Nothing to show.")); term::print(term::format::italic("Nothing to show."));
return Ok(()); return Ok(());
@ -389,27 +388,26 @@ fn list(
by_timestamp.then(by_id) by_timestamp.then(by_id)
}); });
let mut t = term::Table::new(term::table::TableOptions::bordered()); let mut table = term::Table::new(term::table::TableOptions::bordered());
t.push([ table.push([
term::format::dim(String::from("")), term::format::dim(String::from("")).into(),
term::format::bold(String::from("ID")), term::format::bold(String::from("ID")).into(),
term::format::bold(String::from("Title")), term::format::bold(String::from("Title")).into(),
term::format::bold(String::from("Author")), term::format::bold(String::from("Author")).into(),
term::format::bold(String::new()), term::format::bold(String::new()).into(),
term::format::bold(String::from("Tags")), term::format::bold(String::from("Tags")).into(),
term::format::bold(String::from("Assignees")), term::format::bold(String::from("Assignees")).into(),
term::format::bold(String::from("Opened")), term::format::bold(String::from("Opened")).into(),
]); ]);
t.divider(); table.divider();
let store = profile.tracking()?; let aliases = profile.aliases()?;
for (id, issue) in all { for (id, issue) in all {
let assigned: String = issue let assigned: String = issue
.assigned() .assigned()
.map(|ref p| { .map(|ref p| {
if let Ok(Some(alias)) = store.node_policy(p).map(|node| node.and_then(|n| n.alias)) if let Some(alias) = aliases.alias(p) {
{
format!("{alias} ({})", term::format::did(p)) format!("{alias} ({})", term::format::did(p))
} else { } else {
term::format::did(p).to_string() term::format::did(p).to_string()
@ -422,33 +420,33 @@ fn list(
tags.sort(); tags.sort();
let author = issue.author().id; let author = issue.author().id;
let alias = store.node_policy(&author)?.and_then(|node| node.alias); let alias = aliases.alias(&author);
let display = Author::new(&author, alias, profile);
t.push([ table.push([
match issue.state() { match issue.state() {
State::Open => term::format::positive("").into(), State::Open => term::format::positive("").into(),
State::Closed { .. } => term::format::negative("").into(), State::Closed { .. } => term::format::negative("").into(),
}, },
term::format::tertiary(term::format::cob(&id)).to_owned(), term::format::tertiary(term::format::cob(&id))
term::format::default(issue.title().to_owned()), .to_owned()
term::format::did(&issue.author().id).dim(), .into(),
if author.as_key() == &me { term::format::default(issue.title().to_owned()).into(),
term::format::primary("(you)".to_owned()) term::format::did(&issue.author().id).dim().into(),
} else if let Some(alias) = alias { display.alias(),
term::format::primary(alias) term::format::secondary(tags.join(", ")).into(),
} else {
term::format::default(String::new())
},
term::format::secondary(tags.join(", ")),
if assigned.is_empty() { if assigned.is_empty() {
term::format::dim(String::default()) term::format::dim(String::default()).into()
} else { } else {
term::format::default(assigned.to_string()) term::format::default(assigned.to_string()).into()
}, },
term::format::timestamp(&issue.timestamp()).dim().italic(), term::format::timestamp(&issue.timestamp())
.dim()
.italic()
.into(),
]); ]);
} }
t.print(); table.print();
Ok(()) Ok(())
} }