cli: Improve `rad issue show` output

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2023-04-26 13:09:23 +02:00 committed by Alexis Sellier
parent 83547f9c8a
commit 730eaa00ca
No known key found for this signature in database
5 changed files with 108 additions and 37 deletions

View File

@ -5,12 +5,12 @@ Let's say the new car you are designing with your peers has a problem with its f
``` ```
$ rad issue open --title "flux capacitor underpowered" --description "Flux capacitor power requirements exceed current supply" --no-announce $ rad issue open --title "flux capacitor underpowered" --description "Flux capacitor power requirements exceed current supply" --no-announce
title: flux capacitor underpowered ╭─────────────────────────────────────────────────────────╮
state: open │ Title flux capacitor underpowered │
tags: [] │ Status open │
assignees: [] │ │
│ Flux capacitor power requirements exceed current supply │
Flux capacitor power requirements exceed current supply ╰─────────────────────────────────────────────────────────╯
``` ```
The issue is now listed under our project. The issue is now listed under our project.
@ -28,12 +28,12 @@ Show the issue information issue.
``` ```
$ rad issue show 2e8c1bf $ rad issue show 2e8c1bf
title: flux capacitor underpowered ╭─────────────────────────────────────────────────────────╮
state: open │ Title flux capacitor underpowered │
tags: [] │ Status open │
assignees: [] │ │
│ Flux capacitor power requirements exceed current supply │
Flux capacitor power requirements exceed current supply ╰─────────────────────────────────────────────────────────╯
``` ```

View File

@ -9,12 +9,13 @@ We can now show the issue to check whether those tags were added:
``` ```
$ rad issue show 2e8c1bf3fe0532a314778357c886608a966a34bd $ rad issue show 2e8c1bf3fe0532a314778357c886608a966a34bd
title: flux capacitor underpowered ╭─────────────────────────────────────────────────────────╮
state: open │ Title flux capacitor underpowered │
tags: [bug, good-first-issue] │ Tags bug, good-first-issue │
assignees: [] │ Status open │
│ │
Flux capacitor power requirements exceed current supply │ Flux capacitor power requirements exceed current supply │
╰─────────────────────────────────────────────────────────╯
``` ```
Untagging an issue is very similar: Untagging an issue is very similar:
@ -27,10 +28,11 @@ Notice that the `good-first-issue` tag has disappeared:
``` ```
$ rad issue show 2e8c1bf3fe0532a314778357c886608a966a34bd $ rad issue show 2e8c1bf3fe0532a314778357c886608a966a34bd
title: flux capacitor underpowered ╭─────────────────────────────────────────────────────────╮
state: open │ Title flux capacitor underpowered │
tags: [bug] │ Tags bug │
assignees: [] │ Status open │
│ │
Flux capacitor power requirements exceed current supply │ Flux capacitor power requirements exceed current supply │
╰─────────────────────────────────────────────────────────╯
``` ```

View File

@ -5,12 +5,12 @@ Let's say the new car you are designing with your peers has a problem with its f
``` ```
$ rad issue open --title "flux capacitor underpowered" --description "Flux capacitor power requirements exceed current supply" --no-announce $ rad issue open --title "flux capacitor underpowered" --description "Flux capacitor power requirements exceed current supply" --no-announce
title: flux capacitor underpowered ╭─────────────────────────────────────────────────────────╮
state: open │ Title flux capacitor underpowered │
tags: [] │ Status open │
assignees: [] │ │
│ Flux capacitor power requirements exceed current supply │
Flux capacitor power requirements exceed current supply ╰─────────────────────────────────────────────────────────╯
``` ```
The issue is now listed under our project. The issue is now listed under our project.
@ -46,6 +46,19 @@ $ rad issue list --assigned
╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
``` ```
In addition, you can see that when you run `rad issue show` you are listed under the `Assignees`.
```
$ rad issue show b05e945
╭─────────────────────────────────────────────────────────╮
│ Title flux capacitor underpowered │
│ Assignees z6Mkt67…v4N1tRk │
│ Status open │
│ │
│ Flux capacitor power requirements exceed current supply │
╰─────────────────────────────────────────────────────────╯
```
Note: this can always be undone with the `unassign` subcommand. Note: this can always be undone with the `unassign` subcommand.
Great, now we have communicated to the world about our car's defect. Great, now we have communicated to the world about our car's defect.

View File

@ -11,6 +11,8 @@ use radicle::node::Handle;
use radicle::prelude::Did; use radicle::prelude::Did;
use radicle::storage::WriteStorage; use radicle::storage::WriteStorage;
use radicle::{cob, Node}; use radicle::{cob, Node};
use radicle_term::table::TableOptions;
use radicle_term::{Paint, Table, VStack};
use crate::git::Rev; use crate::git::Rev;
use crate::terminal as term; use crate::terminal as term;
@ -406,14 +408,58 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
fn show_issue(issue: &issue::Issue) -> anyhow::Result<()> { fn show_issue(issue: &issue::Issue) -> anyhow::Result<()> {
let tags: Vec<String> = issue.tags().cloned().map(|t| t.into()).collect(); let tags: Vec<String> = issue.tags().cloned().map(|t| t.into()).collect();
let assignees: Vec<String> = issue.assigned().map(|a| a.to_string()).collect(); let assignees: Vec<String> = issue.assigned().map(|a| term::format::did(&a).to_string()).collect();
term::info!("title: {}", issue.title()); let mut attrs = Table::<2, Paint<String>>::new(TableOptions {
term::info!("state: {}", issue.state()); spacing: 2,
term::info!("tags: [{}]", tags.join(", ")); ..TableOptions::default()
term::info!("assignees: [{}]", assignees.join(", ")); });
term::blank();
term::info!("{}", issue.description().unwrap_or_default()); attrs.push([
term::format::tertiary("Title".to_owned()),
term::format::bold(issue.title().to_owned()),
]);
if !tags.is_empty() {
attrs.push([
term::format::tertiary("Tags".to_owned()),
term::format::secondary(tags.join(", ")),
]);
}
if !assignees.is_empty() {
attrs.push([
term::format::tertiary("Assignees".to_owned()),
term::format::dim(assignees.join(", ")),
]);
}
attrs.push([
term::format::tertiary("Status".to_owned()),
match issue.state() {
issue::State::Open => term::format::positive("open".to_owned()),
issue::State::Closed { reason } => term::format::default(format!(
"{} {}",
term::format::negative("closed"),
term::format::default(format!("as {reason}"))
)),
},
]);
let description = issue.description().unwrap_or_default();
let widget = VStack::default()
.border(Some(term::colors::FAINT))
.child(attrs)
.children(if !description.is_empty() {
vec![
term::Label::blank().boxed(),
term::textarea(term::format::dim(description)).boxed(),
]
} else {
vec![]
});
widget.print();
Ok(()) Ok(())
} }

View File

@ -48,6 +48,16 @@ pub enum CloseReason {
Solved, Solved,
} }
impl std::fmt::Display for CloseReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let reason = match self {
Self::Other => "unspecified",
Self::Solved => "solved",
};
write!(f, "{reason}")
}
}
/// Issue state. /// Issue state.
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "status")] #[serde(rename_all = "camelCase", tag = "status")]