Address argus review on #1938's reopen verb: public fns returning Result need a # Errors doc per the workspace convention. Document the patch_json and print_json failure modes.
35 lines
1,006 B
Rust
35 lines
1,006 B
Rust
//! `reopen <number>` — reopen a closed issue or PR.
|
|
//!
|
|
//! Mirror of `close`: sends a PATCH setting the issue/PR `state` back to
|
|
//! `open`. PRs share the issue number space, so the same `/issues/<n>`
|
|
//! endpoint reopens either.
|
|
|
|
use anyhow::Result;
|
|
use clap::Args as ClapArgs;
|
|
use serde_json::json;
|
|
|
|
use crate::client::Client;
|
|
use crate::verbs::print_json;
|
|
|
|
#[derive(ClapArgs)]
|
|
pub struct Args {
|
|
/// Issue or PR number.
|
|
pub(crate) number: u64,
|
|
}
|
|
|
|
/// # Errors
|
|
///
|
|
/// Returns an error when the `PATCH /repos/{repo}/issues/{number}` request
|
|
/// fails (network / non-success status from `patch_json`) or when emitting
|
|
/// the JSON summary via `print_json` fails.
|
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
|
let repo = client.repo();
|
|
let resp = client.patch_json(
|
|
&format!("/repos/{repo}/issues/{}", args.number),
|
|
&json!({ "state": "open" }),
|
|
)?;
|
|
print_json(&json!({
|
|
"number": resp.get("number"),
|
|
"state": resp.get("state"),
|
|
}))
|
|
}
|