refactor(hive-forge): port CLI verbs to forgejo-api
This commit is contained in:
parent
b8a3927c43
commit
4636987469
36 changed files with 1463 additions and 1153 deletions
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::Args as ClapArgs;
|
||||
use serde_json::Value;
|
||||
use forgejo_api::structs::{IssueGetCommentsQuery, StateType};
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::client::{Client, index};
|
||||
use crate::notify;
|
||||
|
||||
#[derive(ClapArgs)]
|
||||
|
|
@ -19,16 +19,24 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
// Reading the thread clears its unread notification so the
|
||||
// read-before-comment guard (in `comment`) lets a reply through.
|
||||
notify::mark_read_best_effort(client, repo, args.number);
|
||||
let issue = client.get_json(&format!("/repos/{repo}/issues/{}", args.number))?;
|
||||
let title = issue.get("title").and_then(Value::as_str).unwrap_or("");
|
||||
let body = issue.get("body").and_then(Value::as_str).unwrap_or("");
|
||||
let state = issue.get("state").and_then(Value::as_str).unwrap_or("?");
|
||||
let (owner, name) = client.owner_repo()?;
|
||||
let issue = client
|
||||
.api()
|
||||
.issue_get_issue(owner, name, index(args.number)?)
|
||||
.send()?;
|
||||
let title = issue.title.as_deref().unwrap_or("");
|
||||
let body = issue.body.as_deref().unwrap_or("");
|
||||
let state = match issue.state {
|
||||
Some(StateType::Open) => "open",
|
||||
Some(StateType::Closed) => "closed",
|
||||
None => "?",
|
||||
};
|
||||
let user = issue
|
||||
.get("user")
|
||||
.and_then(|u| u.get("login"))
|
||||
.and_then(Value::as_str)
|
||||
.user
|
||||
.as_ref()
|
||||
.and_then(|u| u.login.as_deref())
|
||||
.unwrap_or("?");
|
||||
let kind = if issue.get("pull_request").is_some_and(|p| !p.is_null()) {
|
||||
let kind = if issue.pull_request.is_some() {
|
||||
"PR"
|
||||
} else {
|
||||
"issue"
|
||||
|
|
@ -39,23 +47,28 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
println!();
|
||||
println!("{body}");
|
||||
}
|
||||
let comments = client.get_json(&format!(
|
||||
"/repos/{repo}/issues/{}/comments?limit=50",
|
||||
args.number
|
||||
))?;
|
||||
let arr = comments.as_array().cloned().unwrap_or_default();
|
||||
if !arr.is_empty() {
|
||||
let (_, comments) = client
|
||||
.api()
|
||||
.issue_get_comments(
|
||||
owner,
|
||||
name,
|
||||
index(args.number)?,
|
||||
IssueGetCommentsQuery::default(),
|
||||
)
|
||||
.page_size(50)
|
||||
.send()?;
|
||||
if !comments.is_empty() {
|
||||
println!();
|
||||
println!("---");
|
||||
println!("## Comments ({})", arr.len());
|
||||
println!("## Comments ({})", comments.len());
|
||||
println!();
|
||||
for c in &arr {
|
||||
for c in &comments {
|
||||
let cu = c
|
||||
.get("user")
|
||||
.and_then(|u| u.get("login"))
|
||||
.and_then(Value::as_str)
|
||||
.user
|
||||
.as_ref()
|
||||
.and_then(|u| u.login.as_deref())
|
||||
.unwrap_or("?");
|
||||
let cb = c.get("body").and_then(Value::as_str).unwrap_or("");
|
||||
let cb = c.body.as_deref().unwrap_or("");
|
||||
println!("**{cu}**: {cb}");
|
||||
println!();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue