hive-forge: drop the subscription --ignore change (covered by #5053)
This commit is contained in:
parent
6e32b432ec
commit
4d164819b3
2 changed files with 11 additions and 46 deletions
|
|
@ -1278,7 +1278,7 @@ Get/set this user's watch subscription on a repo, or --list all watched repos
|
||||||
###### **Options:**
|
###### **Options:**
|
||||||
|
|
||||||
* `--watch` — Subscribe (watch the repo)
|
* `--watch` — Subscribe (watch the repo)
|
||||||
* `--ignore` — Not supported: the forge API has no ignore endpoint. Errors; use `--unwatch` to stop notifications
|
* `--ignore` — Mute (mark ignored)
|
||||||
* `--unwatch` — Unsubscribe (clear watch + ignore)
|
* `--unwatch` — Unsubscribe (clear watch + ignore)
|
||||||
* `--list` — List every repo the current user watches (ignores `[repo]`)
|
* `--list` — List every repo the current user watches (ignores `[repo]`)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//! repo the user watches (`--list`, for auditing the notification
|
//! repo the user watches (`--list`, for auditing the notification
|
||||||
//! firehose).
|
//! firehose).
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
use anyhow::Result;
|
||||||
use clap::Args as ClapArgs;
|
use clap::Args as ClapArgs;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
|
@ -21,8 +21,7 @@ pub struct Args {
|
||||||
/// Subscribe (watch the repo).
|
/// Subscribe (watch the repo).
|
||||||
#[arg(long, group = "action")]
|
#[arg(long, group = "action")]
|
||||||
watch: bool,
|
watch: bool,
|
||||||
/// Not supported: the forge API has no ignore endpoint. Errors; use
|
/// Mute (mark ignored).
|
||||||
/// `--unwatch` to stop notifications.
|
|
||||||
#[arg(long, group = "action")]
|
#[arg(long, group = "action")]
|
||||||
ignore: bool,
|
ignore: bool,
|
||||||
/// Unsubscribe (clear watch + ignore).
|
/// Unsubscribe (clear watch + ignore).
|
||||||
|
|
@ -33,26 +32,14 @@ pub struct Args {
|
||||||
list: bool,
|
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
|
/// Run the `subscription` verb: `--list` all watched repos, set the
|
||||||
/// current repo's watch (`--watch` / `--ignore` / `--unwatch`), or get
|
/// current repo's watch (`--watch` / `--ignore` / `--unwatch`), or get
|
||||||
/// its current state.
|
/// its current state.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Fails on `--ignore` (unsupported). Propagates transport / non-2xx
|
/// Propagates transport / non-2xx errors from the Forgejo client calls
|
||||||
/// errors from the Forgejo client calls and from `print_json`.
|
/// and from `print_json`.
|
||||||
pub fn run(client: &Client, args: Args) -> Result<()> {
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||||
reject_ignore(&args)?;
|
|
||||||
if args.list {
|
if args.list {
|
||||||
// List every repo the authed user watches, so an agent can audit
|
// List every repo the authed user watches, so an agent can audit
|
||||||
// its notification firehose and decide what to `--unwatch`. Not
|
// its notification firehose and decide what to `--unwatch`. Not
|
||||||
|
|
@ -85,9 +72,12 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||||
println!("unsubscribed");
|
println!("unsubscribed");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if args.watch {
|
if args.watch || args.ignore {
|
||||||
// Forgejo's PUT subscription endpoint takes no body: it always
|
// Forgejo's PUT subscription endpoint takes no body — it always
|
||||||
// subscribes (watch).
|
// 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.
|
||||||
let resp = client
|
let resp = client
|
||||||
.api()
|
.api()
|
||||||
.user_current_put_subscription(owner, name)
|
.user_current_put_subscription(owner, name)
|
||||||
|
|
@ -112,28 +102,3 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||||
Err(e) => Err(e.into()),
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue