From 6c08c8a25c97d682653a4f5e03416a307ef3d00a Mon Sep 17 00:00:00 2001 From: Cyborus Date: Wed, 17 Apr 2024 21:12:29 -0400 Subject: [PATCH 1/2] add proper readout for `repo info` --- src/repo.rs | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/src/repo.rs b/src/repo.rs index bc6f5b0..b0e88c4 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -345,7 +345,97 @@ impl RepoCommand { .ok_or_eyre("couldn't get repo name, please specify")?; let repo = api.repo_get(repo.owner(), repo.name()).await?; - dbg!(repo); + println!("{}", repo.full_name.ok_or_eyre("no full name")?); + + if let Some(parent) = &repo.parent { + println!("Fork of {}", parent.full_name.as_ref().ok_or_eyre("no full name")?); + } + if repo.mirror == Some(true) { + if let Some(original) = &repo.original_url { + println!("Mirror of {original}") + } + } + let desc = repo.description.as_deref().unwrap_or_default(); + if !desc.is_empty() { + if desc.lines().count() > 1 { + println!(); + } + for line in desc.lines() { + println!("> {line}"); + } + } + println!(); + + let lang = repo.language.as_deref().unwrap_or_default(); + if !lang.is_empty() { + println!("Primary language is {lang}"); + } + + let stars = repo.stars_count.unwrap_or_default(); + if stars == 1 { + print!("{stars} star - "); + } else { + print!("{stars} stars - "); + } + + let watchers = repo.watchers_count.unwrap_or_default(); + print!("{watchers} watching - "); + + let forks = repo.forks_count.unwrap_or_default(); + if forks == 1 { + print!("{forks} fork"); + } else { + print!("{forks} forks"); + } + println!(); + + let mut first = true; + if repo.has_issues.unwrap_or_default() && repo.external_tracker.is_none() { + let issues = repo.open_issues_count.unwrap_or_default(); + if issues == 1 { + print!("{issues} issue"); + } else { + print!("{issues} issues"); + } + first = false; + } + if repo.has_pull_requests.unwrap_or_default() { + if !first { + print!(" - "); + } + let pulls = repo.open_pr_counter.unwrap_or_default(); + if pulls == 1 { + print!("{pulls} PR"); + } else { + print!("{pulls} PRs"); + } + first = false; + } + if repo.has_releases.unwrap_or_default() { + if !first { + print!(" - "); + } + let releases = repo.release_counter.unwrap_or_default(); + if releases == 1 { + print!("{releases} release"); + } else { + print!("{releases} releases"); + } + first = false; + } + if !first { + println!(); + } + if let Some(external_tracker) = &repo.external_tracker { + if let Some(tracker_url) = &external_tracker.external_tracker_url { + println!("Issue tracker is at {tracker_url}"); + } + } + + if let Some(html_url) = &repo.html_url { + println!(); + println!("View online at {html_url}"); + } } RepoCommand::Browse { name, remote } => { let repo = RepoInfo::get_current(host_name, name.as_deref(), remote.as_deref())?; From 2587bf948252e277300aad60a8392575f26a9cc9 Mon Sep 17 00:00:00 2001 From: Cyborus Date: Wed, 17 Apr 2024 21:24:45 -0400 Subject: [PATCH 2/2] format --- src/repo.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/repo.rs b/src/repo.rs index b0e88c4..5f2fcb7 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -348,7 +348,10 @@ impl RepoCommand { println!("{}", repo.full_name.ok_or_eyre("no full name")?); if let Some(parent) = &repo.parent { - println!("Fork of {}", parent.full_name.as_ref().ok_or_eyre("no full name")?); + println!( + "Fork of {}", + parent.full_name.as_ref().ok_or_eyre("no full name")? + ); } if repo.mirror == Some(true) { if let Some(original) = &repo.original_url {