Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/hive-forge/src/verbs/repo_add_collaborator.rs
iris e82a735745 docs: fix write-good.So/ThereIs/Weasel lint findings
Fixes the "obvious ones first" slice of #4042 (mara: do the obvious
ones first) -- 81 hits across write-good.So, write-good.ThereIs, and
write-good.Weasel, all in docs/. Each is a genuine sentence rewrite
(lead with the real subject instead of "There is/are", drop a
sentence-initial "So ", replace a vague intensifier), not a blind
regex substitution -- read every hit in its real file context before
touching it.

3 of the 81 hits were in CI-generated CLI docs (docs/tools/{hivectl,
swarmctl,forge}-cli.md) -- fixed at the clap #[arg(...)]/doc-comment
source in hivectl/src/cli.rs, swarmctl/src/main.rs, and
hive-forge/src/verbs/repo_add_collaborator.rs, then regenerated via
each crate's `markdown-docs` subcommand so CI's freshness check stays
green.

Verified: fresh vale re-run shows 0 remaining So/ThereIs/Weasel hits
and no new hits introduced (983->982, exactly the one incidental fix
this pass also picked up at docs/scheduler/observability.md:48).
cargo fmt --check and clippy clean on the three touched crates.

Remaining write-good backlog (Passive: 726, TooWordy: 207) is
judgment-heavy and left for a follow-up slice of #4042, not bulk-
rewritten here.
2026-09-07 17:49:27 +02:00

82 lines
2.6 KiB
Rust

//! `repo-add-collaborator <user> [--permission read|write|admin] [-r <repo>]`
//! — add `<user>` as a collaborator on the active repo (see
//! `client::Client::from_env` for how it resolves). Prints a one-line
//! confirmation.
//!
//! Wraps `PUT /api/v1/repos/{owner}/{repo}/collaborators/{collaborator}`.
//! A fresh agent-namespace repo (see `repo-create`) usually needs peers
//! added before they can collaborate; this is the companion verb.
use anyhow::Result;
use clap::Args as ClapArgs;
use clap::ValueEnum;
use forgejo_api::structs::{AddCollaboratorOption, AddCollaboratorOptionPermission};
use crate::client::Client;
/// Collaborator permission level accepted by Forgejo.
#[derive(Clone, Copy, ValueEnum)]
pub enum Permission {
/// Pull (read-only) access.
Read,
/// Push (read/write) access.
Write,
/// Full administrative access to the repo.
Admin,
}
impl Permission {
/// The wire string Forgejo's API expects (used for the printed
/// confirmation).
fn as_api(self) -> &'static str {
match self {
Permission::Read => "read",
Permission::Write => "write",
Permission::Admin => "admin",
}
}
/// The typed permission for the request body.
fn as_option(self) -> AddCollaboratorOptionPermission {
match self {
Permission::Read => AddCollaboratorOptionPermission::Read,
Permission::Write => AddCollaboratorOptionPermission::Write,
Permission::Admin => AddCollaboratorOptionPermission::Admin,
}
}
}
#[derive(ClapArgs)]
pub struct Args {
/// Collaborator's forge login to add.
user: String,
/// Permission level to grant (default: write — a freshly added
/// collaborator typically needs to push).
#[arg(long, value_enum, default_value_t = Permission::Write)]
permission: Permission,
}
/// # Errors
///
/// Propagates any transport error from the Forgejo REST call (network
/// unreachable, 4xx/5xx response such as an unknown user or insufficient
/// permission on the repo, token missing/invalid) and any I/O error from
/// writing the confirmation to stdout.
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo()?;
let (owner, name) = client.owner_repo()?;
let perm = args.permission.as_api();
client
.api()
.repo_add_collaborator(
owner,
name,
&args.user,
AddCollaboratorOption {
permission: Some(args.permission.as_option()),
},
)
.send()?;
println!("added {} to {repo} ({perm})", args.user);
Ok(())
}