Watch
0
0
Fork
You've already forked hyperhive
0

hive-forge: subscription --ignore errors instead of subscribing; warn on --draft; always print agit PR URL

This commit is contained in:
atlas 2026-10-09 11:43:21 +02:00 • committed by mara
commit 6e32b432ec
3 changed files with 71 additions and 17 deletions

View file

@ -3,7 +3,7 @@
//! repo the user watches (`--list`, for auditing the notification
//! firehose).
use anyhow::Result;
use anyhow::{Result, bail};
use clap::Args as ClapArgs;
use serde_json::json;
@ -21,7 +21,8 @@ pub struct Args {
/// Subscribe (watch the repo).
#[arg(long, group = "action")]
watch: bool,
/// Mute (mark ignored).
/// Not supported: the forge API has no ignore endpoint. Errors; use
/// `--unwatch` to stop notifications.
#[arg(long, group = "action")]
ignore: bool,
/// Unsubscribe (clear watch + ignore).
@ -32,14 +33,26 @@ pub struct Args {
list: bool,
}
/// `--ignore` has no Forgejo endpoint; fail rather than subscribe.
fn reject_ignore(args: &Args) -> Result<()> {
if args.ignore {
bail!(
"--ignore is not supported: the forge API has no ignore endpoint; \
use `--unwatch` to stop notifications"
);
}
Ok(())
}
/// Run the `subscription` verb: `--list` all watched repos, set the
/// current repo's watch (`--watch` / `--ignore` / `--unwatch`), or get
/// its current state.
///
/// # Errors
/// Propagates transport / non-2xx errors from the Forgejo client calls
/// and from `print_json`.
/// Fails on `--ignore` (unsupported). Propagates transport / non-2xx
/// errors from the Forgejo client calls and from `print_json`.
pub fn run(client: &Client, args: Args) -> Result<()> {
reject_ignore(&args)?;
if args.list {
// List every repo the authed user watches, so an agent can audit
// its notification firehose and decide what to `--unwatch`. Not
@ -72,12 +85,9 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
println!("unsubscribed");
return Ok(());
}
if args.watch || args.ignore {
// Forgejo's PUT subscription endpoint takes no body — it always
// subscribes (watch). The old raw client sent a
// `{subscribed, ignored}` body which the server ignored, so
// `--ignore` has always behaved like `--watch` server-side; the
// typed call just makes that explicit.
if args.watch {
// Forgejo's PUT subscription endpoint takes no body: it always
// subscribes (watch).
let resp = client
.api()
.user_current_put_subscription(owner, name)
@ -102,3 +112,28 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
Err(e) => Err(e.into()),
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[derive(Parser)]
struct Cli {
#[command(flatten)]
args: Args,
}
#[test]
fn ignore_is_rejected_pointing_at_unwatch() {
let cli = Cli::parse_from(["x", "--ignore"]);
let err = reject_ignore(&cli.args).unwrap_err().to_string();
assert!(err.contains("--unwatch"), "{err}");
}
#[test]
fn watch_is_not_rejected() {
let cli = Cli::parse_from(["x", "--watch"]);
assert!(reject_ignore(&cli.args).is_ok());
}
}