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
|
|
@ -46,6 +46,7 @@ pub mod view;
|
|||
use std::fmt::Write as _;
|
||||
|
||||
use anyhow::Result;
|
||||
use forgejo_api::structs::Attachment;
|
||||
use serde_json::{Value, json};
|
||||
use time::OffsetDateTime;
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
|
|
@ -375,6 +376,38 @@ pub(crate) fn dependency_summaries(
|
|||
.collect())
|
||||
}
|
||||
|
||||
/// A single attachment as one display line — `[file: <name>] <url>`,
|
||||
/// mirroring the `[file: ...]` marker convention `read_room` already
|
||||
/// uses for matrix attachments. `None` when the attachment has no
|
||||
/// download URL (shouldn't happen server-side, but a missing pointer
|
||||
/// is worse silently dropped than shown as "?").
|
||||
///
|
||||
/// Forgejo already returns `assets` inline on the same `Comment`/`Issue`
|
||||
/// fetch every render path here already makes — this just reads a field
|
||||
/// that was sitting unused, the gap that made an attachment link
|
||||
/// unreadable from a non-visual CLI read without guessing the UUID by
|
||||
/// hand (hit in practice on the swarm-controller extraction thread).
|
||||
pub(crate) fn attachment_line(a: &Attachment) -> Option<String> {
|
||||
let name = a.name.as_deref().unwrap_or("?");
|
||||
let url = a.browser_download_url.as_ref()?;
|
||||
Some(format!("[file: {name}] {url}"))
|
||||
}
|
||||
|
||||
/// JSON form of an attachment list (`{"name", "url"}` per entry), for
|
||||
/// `--json` output — same data [`attachment_line`] renders as text.
|
||||
pub(crate) fn attachment_json(assets: Option<&[Attachment]>) -> Vec<Value> {
|
||||
assets
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|a| {
|
||||
json!({
|
||||
"name": a.name,
|
||||
"url": a.browser_download_url.as_ref().map(ToString::to_string),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{pct_encode, reviewed_older_head};
|
||||
|
|
|
|||
Loading…
Reference in a new issue