Rebuild on forge's own notification read-state instead of the local seen-cursor mirror (operator-nacked: mirrors state forge owns + drifts on restart). - comment refuses to post when forge has an unread notification for the thread (someone commented since you last read it); --force overrides. Degrades open if the notification check itself fails. - comments / view mark the thread's notification read (the "I've seen it" signal), clearing the guard for a subsequent reply. - new crate::notify (no local file): unread_thread_id pages repo-scoped unread notifications (newest-first, capped) + subject-url number match; mark_thread_read via the new client.patch_no_content. Pairs with the forge_notify harness change (#1895, merged) that leaves delivered notifications unread until the agent actually reads. Covers pr/issue comment too (they delegate to comment::run).
64 lines
2 KiB
Rust
64 lines
2 KiB
Rust
//! `view <number> [repo]` — dump title + body + all comments as
|
|
//! markdown.
|
|
|
|
use anyhow::Result;
|
|
use clap::Args as ClapArgs;
|
|
use serde_json::Value;
|
|
|
|
use crate::client::Client;
|
|
use crate::notify;
|
|
|
|
#[derive(ClapArgs)]
|
|
pub struct Args {
|
|
/// Issue or PR number.
|
|
pub(crate) number: u64,
|
|
}
|
|
|
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
|
let repo = client.repo();
|
|
// 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 user = issue
|
|
.get("user")
|
|
.and_then(|u| u.get("login"))
|
|
.and_then(Value::as_str)
|
|
.unwrap_or("?");
|
|
let kind = if issue.get("pull_request").is_some_and(|p| !p.is_null()) {
|
|
"PR"
|
|
} else {
|
|
"issue"
|
|
};
|
|
println!("# {kind} #{} [{state}] by {user}", args.number);
|
|
println!("{title}");
|
|
if !body.is_empty() {
|
|
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() {
|
|
println!();
|
|
println!("---");
|
|
println!("## Comments ({})", arr.len());
|
|
println!();
|
|
for c in &arr {
|
|
let cu = c
|
|
.get("user")
|
|
.and_then(|u| u.get("login"))
|
|
.and_then(Value::as_str)
|
|
.unwrap_or("?");
|
|
let cb = c.get("body").and_then(Value::as_str).unwrap_or("");
|
|
println!("**{cu}**: {cb}");
|
|
println!();
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|