summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-07-06 17:31:31 +0200
committerCyborus <cyborus@cyborus.xyz>2024-07-06 17:31:31 +0200
commit6b78a23ca4be95e184f024fc37e20d7a3f47fad0 (patch)
tree54decb109f44d8f621abad3db677cafe192ddcaf
parentMerge pull request 'add `FJ_FALLBACK_HOST` env var' (#82) from host-fallback ... (diff)
downloadforgejo-cli-6b78a23ca4be95e184f024fc37e20d7a3f47fad0.tar.xz
forgejo-cli-6b78a23ca4be95e184f024fc37e20d7a3f47fad0.zip
feat(display): bring issue printing to visual parity with PR printing
-rw-r--r--src/issues.rs48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/issues.rs b/src/issues.rs
index d9667d4..92f0e06 100644
--- a/src/issues.rs
+++ b/src/issues.rs
@@ -236,7 +236,26 @@ async fn create_issue(
}
pub async fn view_issue(repo: &RepoName, api: &Forgejo, id: u64) -> eyre::Result<()> {
+ let crate::SpecialRender {
+ dash,
+
+ bright_red,
+ bright_green,
+ yellow,
+ dark_grey,
+ white,
+ reset,
+ ..
+ } = crate::special_render();
+
let issue = api.issue_get_issue(repo.owner(), repo.name(), id).await?;
+
+ // if it's a pull request, display it as one instead
+ if issue.pull_request.is_some() {
+ crate::prs::view_pr(repo, api, Some(id)).await?;
+ return Ok(());
+ }
+
let title = issue
.title
.as_ref()
@@ -249,11 +268,32 @@ pub async fn view_issue(repo: &RepoName, api: &Forgejo, id: u64) -> eyre::Result
.login
.as_ref()
.ok_or_else(|| eyre::eyre!("user does not have login"))?;
- println!("#{}: {}", id, title);
- println!("By {}", username);
+ let state = issue
+ .state
+ .ok_or_else(|| eyre::eyre!("pr does not have state"))?;
+ let comments = issue.comments.unwrap_or_default();
+
+ println!("{yellow}{title} {dark_grey}#{id}{reset}");
+ print!("By {white}{username}{reset} {dash} ");
+
+ use forgejo_api::structs::StateType;
+ match state {
+ StateType::Open => println!("{bright_green}Open{reset}"),
+ StateType::Closed => println!("{bright_red}Closed{reset}"),
+ };
+
if let Some(body) = &issue.body {
- println!();
- println!("{}", crate::markdown(body));
+ if !body.is_empty() {
+ println!();
+ println!("{}", crate::markdown(body));
+ }
+ }
+ println!();
+
+ if comments == 1 {
+ println!("1 comment");
+ } else {
+ println!("{comments} comments");
}
Ok(())
}