Compare commits
3 changed files with 3 additions and 44 deletions
|
|
@ -81,7 +81,6 @@ hive-forge ci-log --run 51 # print a CI run's job step logs (r
|
||||||
hive-forge ci-rerun --pr 42 # re-run CI without an empty commit (dispatches a fresh run; --run n / --branch name also work)
|
hive-forge ci-rerun --pr 42 # re-run CI without an empty commit (dispatches a fresh run; --run n / --branch name also work)
|
||||||
hive-forge subscription --watch # subscribe to repo notifications
|
hive-forge subscription --watch # subscribe to repo notifications
|
||||||
hive-forge subscription --unwatch # unsubscribe
|
hive-forge subscription --unwatch # unsubscribe
|
||||||
hive-forge subscription --list # list every repo you watch (audit the notification firehose)
|
|
||||||
hive-forge -r internal/knowledge clone # clone with creds auto-injected
|
hive-forge -r internal/knowledge clone # clone with creds auto-injected
|
||||||
hive-forge -r internal/knowledge pr-create --agit --topic foo --title "..." # open PR via AGit (no fork)
|
hive-forge -r internal/knowledge pr-create --agit --topic foo --title "..." # open PR via AGit (no fork)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ enum Verb {
|
||||||
/// Print the unified diff for a PR.
|
/// Print the unified diff for a PR.
|
||||||
#[command(hide = true)]
|
#[command(hide = true)]
|
||||||
Diff(verbs::diff::Args),
|
Diff(verbs::diff::Args),
|
||||||
/// Get/set this user's watch subscription on a repo, or --list all watched repos.
|
/// Get or set this user's watch subscription on a repo.
|
||||||
Subscription(verbs::subscription::Args),
|
Subscription(verbs::subscription::Args),
|
||||||
/// List timeline events on an issue or PR (closes, label adds,
|
/// List timeline events on an issue or PR (closes, label adds,
|
||||||
/// assignments, commit refs, pushes, etc.) — the audit trail
|
/// assignments, commit refs, pushes, etc.) — the audit trail
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
//! `subscription [--watch|--ignore|--unwatch|--list] [repo]` — get or
|
//! `subscription [--watch|--ignore|--unwatch] [repo]` — get or set
|
||||||
//! set the current user's watch subscription for a repo, or list every
|
//! the current user's watch subscription for a repo.
|
||||||
//! repo the user watches (`--list`, for auditing the notification
|
|
||||||
//! firehose).
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Args as ClapArgs;
|
use clap::Args as ClapArgs;
|
||||||
|
|
@ -11,12 +9,6 @@ use crate::client::Client;
|
||||||
use crate::verbs::print_json;
|
use crate::verbs::print_json;
|
||||||
|
|
||||||
#[derive(ClapArgs)]
|
#[derive(ClapArgs)]
|
||||||
#[allow(
|
|
||||||
clippy::struct_excessive_bools,
|
|
||||||
reason = "mutually-exclusive clap action flags (group = \"action\"); an \
|
|
||||||
enum would drop the --watch/--ignore/--unwatch/--list flag \
|
|
||||||
ergonomics agents already use"
|
|
||||||
)]
|
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
/// Subscribe (watch the repo).
|
/// Subscribe (watch the repo).
|
||||||
#[arg(long, group = "action")]
|
#[arg(long, group = "action")]
|
||||||
|
|
@ -27,41 +19,9 @@ pub struct Args {
|
||||||
/// Unsubscribe (clear watch + ignore).
|
/// Unsubscribe (clear watch + ignore).
|
||||||
#[arg(long, group = "action")]
|
#[arg(long, group = "action")]
|
||||||
unwatch: bool,
|
unwatch: bool,
|
||||||
/// List every repo the current user watches (ignores `[repo]`).
|
|
||||||
#[arg(long, group = "action")]
|
|
||||||
list: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
|
||||||
/// (`get_json` / `put_json` / `delete`) and from `print_json`.
|
|
||||||
pub fn run(client: &Client, args: Args) -> Result<()> {
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||||
if args.list {
|
|
||||||
// List every repo the authed user watches, so an agent can audit
|
|
||||||
// its notification firehose and decide what to `--unwatch`. Not
|
|
||||||
// repo-scoped. Paginated, with a generous page cap so a
|
|
||||||
// misbehaving server can't spin us forever.
|
|
||||||
const MAX_PAGES: u32 = 50;
|
|
||||||
const PAGE: u32 = 50;
|
|
||||||
let mut watching: Vec<String> = Vec::new();
|
|
||||||
for page in 1..=MAX_PAGES {
|
|
||||||
let v = client.get_json(&format!("/user/subscriptions?page={page}&limit={PAGE}"))?;
|
|
||||||
let arr = v.as_array().cloned().unwrap_or_default();
|
|
||||||
let n = arr.len();
|
|
||||||
watching.extend(
|
|
||||||
arr.iter()
|
|
||||||
.filter_map(|r| r["full_name"].as_str().map(str::to_owned)),
|
|
||||||
);
|
|
||||||
if n < PAGE as usize {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return print_json(&json!({ "watching": watching }));
|
|
||||||
}
|
|
||||||
let repo = client.repo();
|
let repo = client.repo();
|
||||||
if args.unwatch {
|
if args.unwatch {
|
||||||
client.delete(&format!("/repos/{repo}/subscription"), None)?;
|
client.delete(&format!("/repos/{repo}/subscription"), None)?;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue