hyperhive/hive-forge/src/verbs/pr_cmd.rs

103 lines
3.7 KiB
Rust

//! `pr <verb>` — PR-scoped sub-commands. Wraps the per-verb modules under a
//! `pr` parent so `hive-forge pr close 42`, `pr status --pr 42`, etc. read as
//! kind-namespaced commands. The generic verbs that also work on issues
//! (view/comment/comments/close/reopen/labels/assign-committer/timeline) kind-check the number
//! is a PR first (`assert_kind`); the PR-only verbs hit `/pulls/…` and are
//! kind-correct by construction. The flat `pr-*` + bare generic verbs stay as
//! hidden back-compat aliases (see `main.rs`).
use anyhow::Result;
use clap::{Args as ClapArgs, Subcommand};
use crate::client::Client;
use crate::verbs::{self, Kind, assert_kind};
#[derive(ClapArgs)]
pub struct Args {
#[command(subcommand)]
cmd: Cmd,
}
#[derive(Subcommand)]
enum Cmd {
/// Show PR metadata as JSON.
Show(verbs::pr::Args),
/// List the PR's commits as JSON.
Commits(verbs::pr_commits::Args),
/// Create a pull request.
Create(verbs::pr_create::Args),
/// PR health view: mergeable / CI / reviews.
Status(verbs::pr_status::Args),
/// Merge the PR.
Merge(verbs::pr_merge::Args),
/// List a PR's reviews, or submit one.
Reviews(verbs::pr_reviews::Args),
/// Request (or withdraw with `--remove`) a review from a user.
AssignReviewer(verbs::pr_assign_reviewer::Args),
/// Print the PR's unified diff.
Diff(verbs::diff::Args),
/// Show title + body + comments.
View(verbs::view::Args),
/// Post a comment on the PR.
Comment(verbs::comment::Args),
/// List comments on the PR.
Comments(verbs::comments::Args),
/// Close the PR.
Close(verbs::close::Args),
/// Reopen a closed PR.
Reopen(verbs::reopen::Args),
/// List / add / remove labels.
Labels(verbs::labels::Args),
/// Assign or unassign a user (the PR's assignee list).
#[command(alias = "assign")]
AssignCommitter(verbs::assign::Args),
/// List timeline events.
Timeline(verbs::timeline::Args),
}
pub fn run(client: &Client, args: Args) -> Result<()> {
match args.cmd {
// PR-only verbs — kind-correct by construction (hit `/pulls/…`).
Cmd::Show(a) => verbs::pr::run(client, a),
Cmd::Commits(a) => verbs::pr_commits::run(client, a),
Cmd::Create(a) => verbs::pr_create::run(client, a),
Cmd::Status(a) => verbs::pr_status::run(client, a),
Cmd::Merge(a) => verbs::pr_merge::run(client, a),
Cmd::Reviews(a) => verbs::pr_reviews::run(client, a),
Cmd::AssignReviewer(a) => verbs::pr_assign_reviewer::run(client, a),
Cmd::Diff(a) => verbs::diff::run(client, a),
// Generics shared with `issue` — verify the number is a PR first.
Cmd::View(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::view::run(client, a)
}
Cmd::Comment(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::comment::run(client, a)
}
Cmd::Comments(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::comments::run(client, a)
}
Cmd::Close(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::close::run(client, a)
}
Cmd::Reopen(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::reopen::run(client, a)
}
Cmd::Labels(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::labels::run(client, a)
}
Cmd::AssignCommitter(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::assign::run(client, a)
}
Cmd::Timeline(a) => {
assert_kind(client, a.number, Kind::Pr)?;
verbs::timeline::run(client, a)
}
}
}