hive-forge: surface comment/issue attachments in comments/view/comment-show/issue
This commit is contained in:
parent
ecf9ff4d80
commit
6f3ac755e0
5 changed files with 93 additions and 2 deletions
|
|
@ -106,6 +106,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
"url": c.get("html_url"),
|
||||
"kind": c.get("kind").and_then(Value::as_str).unwrap_or("comment"),
|
||||
"state": c.get("state"),
|
||||
"attachments": attachment_json_from_value(c),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
|
@ -131,6 +132,9 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
} else {
|
||||
println!("**{user} @ {ts}**: {body}");
|
||||
}
|
||||
for line in attachment_lines_from_value(c) {
|
||||
println!("{line}");
|
||||
}
|
||||
println!();
|
||||
}
|
||||
if since_clamped {
|
||||
|
|
@ -170,6 +174,42 @@ fn truncation_note(more_before: usize, more_after: usize) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Attachment display lines for a single comment's already-serialized
|
||||
/// `assets` field — the shape this module's merge/render pipeline works
|
||||
/// on (comments arrive as `Value`s, not the typed `Comment` struct, once
|
||||
/// merged with synthesized review entries). Review entries carry no
|
||||
/// `assets` field at all, so they naturally yield nothing here. Mirrors
|
||||
/// [`crate::verbs::attachment_line`]'s `[file: <name>] <url>` format.
|
||||
fn attachment_lines_from_value(c: &Value) -> Vec<String> {
|
||||
c.get("assets")
|
||||
.and_then(Value::as_array)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|a| {
|
||||
let name = a.get("name").and_then(Value::as_str).unwrap_or("?");
|
||||
let url = a.get("browser_download_url").and_then(Value::as_str)?;
|
||||
Some(format!("[file: {name}] {url}"))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// JSON form of [`attachment_lines_from_value`]'s data, for `--json`
|
||||
/// output — same `{"name", "url"}` shape [`crate::verbs::attachment_json`]
|
||||
/// produces from the typed struct.
|
||||
fn attachment_json_from_value(c: &Value) -> Vec<Value> {
|
||||
c.get("assets")
|
||||
.and_then(Value::as_array)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|a| {
|
||||
json!({
|
||||
"name": a.get("name"),
|
||||
"url": a.get("browser_download_url"),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Total comment count on an issue/PR, straight off the issue object.
|
||||
/// Used both to plan `--tail`'s pagination and to report how many
|
||||
/// comments sit outside whatever window ends up shown.
|
||||
|
|
|
|||
Loading…
Reference in a new issue