use std::process::ExitStatus;
use clap::{Parser, Subcommand};
use git_assist::{
command::bisect::{skip_pull_requests, SkipPullRequestsConfigBuilder},
host::{GitHost, GithubApi, SupportedHost},
};
use super::CommonOptions;
#[derive(Subcommand, Eq, PartialEq, Debug)]
pub(crate) enum Command {
SkipPullRequests(SkipPullRequestsCommand),
}
#[derive(Parser, Eq, PartialEq, Debug)]
pub(crate) struct SkipPullRequestsCommand {
#[arg(long)]
pub(crate) remote_url: Option<String>,
#[arg(long, hide = true)]
pub(crate) directory: Option<String>,
#[arg(long)]
pub(crate) good: Option<String>,
#[arg(long)]
pub(crate) bad: Option<String>,
#[arg(long)]
pub(crate) dry_run: bool,
#[command(flatten)]
pub(crate) common: CommonOptions,
}
impl SkipPullRequestsCommand {
pub async fn run(&self) -> anyhow::Result<ExitStatus> {
let config = SkipPullRequestsConfigBuilder::new()
.remote_url(self.remote_url.clone())
.directory(self.directory.clone())
.good(self.good.clone())
.bad(self.bad.clone())
.dry_run(self.dry_run)
.build()?;
let host: Box<dyn GitHost> = match SupportedHost::try_from(&config.repository.parsed_url)? {
SupportedHost::Github => Box::new(GithubApi::authenticated()?),
};
skip_pull_requests(&*host, &config).await
}
}