Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/hive-forge/src/verbs/pr_reviews.rs
atlas 68e30b857c feat(#1137): rich unread summary in loose ends and wake signal
- hive-sh4re: UnreadMatrix gains summary: String field (per-room breakdown)
- hive-matrix-mcp/protocol: add RoomUnread struct + UnreadSummary request
- hive-matrix-mcp/handlers: collect_unread() fetches per-room data;
  single-unread rooms include truncated last-message body + sender;
  multi-unread rooms carry count only
- hive-matrix-mcp/wake: format_unread_summary() builds wake body from
  RoomUnread slice; terse one-liner for single-room/single-message,
  bulleted list for multi-room; always appends read-hint
- hive-matrix-mcp/timeline: wake body now covers all rooms with unread
  at fire time, not just the triggering event; falls back to per-event
  teaser if notification counts haven't updated yet
- hive-ag3nt/mcp: matrix_unread_summary() replaces matrix_unread_rooms();
  UnreadMatrix loose end carries per-room summary lines; render shows
  room breakdown with sender: body for single-unread rooms
2026-06-03 13:56:00 +02:00

88 lines
2.7 KiB
Rust

//! `pr-reviews <number>` — list reviews, or submit one via `--approve` /
//! `--request-changes` / `--comment`.
use anyhow::{Result, bail};
use clap::Args as ClapArgs;
use serde_json::{Value, json};
use crate::client::Client;
use crate::verbs::print_json;
#[derive(ClapArgs)]
pub struct Args {
/// PR number.
number: u64,
/// Approve the PR (submit an APPROVED review).
#[arg(long, conflicts_with_all = ["request_changes", "comment"])]
approve: bool,
/// Request changes on the PR (submit a REQUEST_CHANGES review).
#[arg(long, conflicts_with_all = ["approve", "comment"])]
request_changes: bool,
/// Leave a comment review (submit a COMMENT review).
#[arg(long, conflicts_with_all = ["approve", "request_changes"])]
comment: bool,
/// Optional body / message for the review (used with --approve,
/// --request-changes, or --comment).
#[arg(long, short = 'm')]
body: Option<String>,
}
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo();
let event = if args.approve {
Some("APPROVED")
} else if args.request_changes {
Some("REQUEST_CHANGES")
} else if args.comment {
Some("COMMENT")
} else {
None
};
if let Some(ev) = event {
// Submit a review.
let payload = json!({
"event": ev,
"body": args.body.unwrap_or_default(),
});
let v = client.post_json(
&format!("/repos/{repo}/pulls/{}/reviews", args.number),
&payload,
)?;
// Print a compact summary rather than the full review blob.
let summary = json!({
"id": v.get("id"),
"state": v.get("state"),
"user": v.get("user").and_then(|u| u.get("login")),
});
print_json(&summary)
} else {
if args.body.is_some() {
bail!("--body requires one of --approve / --request-changes / --comment");
}
// List mode (original behaviour).
let v = client.get_json(&format!("/repos/{repo}/pulls/{}/reviews", args.number))?;
let trimmed: Vec<Value> = v
.as_array()
.map(|a| {
a.iter()
.map(|r| {
json!({
"id": r.get("id"),
"state": r.get("state"),
"user": r.get("user").and_then(|u| u.get("login")),
"body": r.get("body"),
"comments_count": r.get("comments_count"),
})
})
.collect()
})
.unwrap_or_default();
print_json(&Value::Array(trimmed))
}
}