Compare commits
5 Commits
main
...
feature/re
Author | SHA1 | Date | |
---|---|---|---|
6196f89342 | |||
ab464fbb6b | |||
e4e33ebda2 | |||
ffc0659a84 | |||
b7a865b48e |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -737,7 +737,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toolkit"
|
||||
version = "0.1.14"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"eyre",
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "toolkit"
|
||||
description = "Toolkit is an opinionated toolkit complementing a personal development workflow. Many of the commands are quite verbose, and well suited for adding to your shell toolbelt"
|
||||
version = "0.1.14"
|
||||
version = "0.1.10"
|
||||
edition = "2021"
|
||||
license-file = "LICENSE"
|
||||
authors = ["Kasper J. Hermansen contact@kjuulh.io"]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::review_backend::{
|
||||
models::{MenuChoice, MergeStrategy, PullRequest, ReviewMenuChoice},
|
||||
models::{MenuChoice, PullRequest, ReviewMenuChoice},
|
||||
DefaultReviewBackend, DynReviewBackend,
|
||||
};
|
||||
|
||||
@ -34,11 +34,7 @@ impl Review {
|
||||
/// 4. Present pr and use delta to view changes
|
||||
/// 5. Approve, open, skip or quit
|
||||
/// 6. Repeat from 4
|
||||
fn run(
|
||||
&self,
|
||||
review_requested: Option<String>,
|
||||
merge_strategy: &Option<MergeStrategy>,
|
||||
) -> eyre::Result<()> {
|
||||
fn run(&self, review_requested: Option<String>) -> eyre::Result<()> {
|
||||
let prs = self.backend.get_prs(review_requested.clone())?;
|
||||
|
||||
let prs_table = Self::generate_prs_table(&prs);
|
||||
@ -46,16 +42,16 @@ impl Review {
|
||||
|
||||
match self.backend.present_menu()? {
|
||||
MenuChoice::Exit => eyre::bail!(ReviewErrors::UserExit),
|
||||
MenuChoice::Begin => match self.review(&prs, &merge_strategy)? {
|
||||
MenuChoice::Begin => match self.review(&prs)? {
|
||||
Some(choice) => match choice {
|
||||
MenuChoice::Exit => eyre::bail!(ReviewErrors::UserExit),
|
||||
MenuChoice::List => return self.run(review_requested.clone(), merge_strategy),
|
||||
MenuChoice::List => return self.run(review_requested.clone()),
|
||||
_ => eyre::bail!("invalid choice"),
|
||||
},
|
||||
None => {}
|
||||
},
|
||||
MenuChoice::Search => todo!(),
|
||||
MenuChoice::List => return self.run(review_requested.clone(), merge_strategy),
|
||||
MenuChoice::List => return self.run(review_requested.clone()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -83,16 +79,12 @@ impl Review {
|
||||
table.to_string()
|
||||
}
|
||||
|
||||
fn review(
|
||||
&self,
|
||||
prs: &Vec<PullRequest>,
|
||||
merge_strategy: &Option<MergeStrategy>,
|
||||
) -> eyre::Result<Option<MenuChoice>> {
|
||||
fn review(&self, prs: &Vec<PullRequest>) -> eyre::Result<Option<MenuChoice>> {
|
||||
for pr in prs {
|
||||
self.backend.clear()?;
|
||||
self.backend.present_pr(pr)?;
|
||||
self.review_pr(pr)?;
|
||||
if let Some(choice) = self.present_pr_menu(pr, merge_strategy)? {
|
||||
if let Some(choice) = self.present_pr_menu(pr)? {
|
||||
return Ok(Some(choice));
|
||||
}
|
||||
}
|
||||
@ -111,21 +103,13 @@ impl Review {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn open_browser(
|
||||
&self,
|
||||
pr: &PullRequest,
|
||||
merge_strategy: &Option<MergeStrategy>,
|
||||
) -> eyre::Result<Option<MenuChoice>> {
|
||||
fn open_browser(&self, pr: &PullRequest) -> eyre::Result<Option<MenuChoice>> {
|
||||
self.backend.pr_open_browser(pr)?;
|
||||
|
||||
self.present_pr_menu(pr, merge_strategy)
|
||||
self.present_pr_menu(pr)
|
||||
}
|
||||
|
||||
fn present_pr_menu(
|
||||
&self,
|
||||
pr: &PullRequest,
|
||||
merge_strategy: &Option<MergeStrategy>,
|
||||
) -> eyre::Result<Option<MenuChoice>> {
|
||||
fn present_pr_menu(&self, pr: &PullRequest) -> eyre::Result<Option<MenuChoice>> {
|
||||
self.backend.present_pr(pr)?;
|
||||
|
||||
match self.backend.present_review_menu(pr)? {
|
||||
@ -133,58 +117,33 @@ impl Review {
|
||||
ReviewMenuChoice::List => return Ok(Some(MenuChoice::List)),
|
||||
ReviewMenuChoice::Approve => {
|
||||
self.approve(pr)?;
|
||||
return self.present_pr_menu(pr, merge_strategy);
|
||||
return self.present_pr_menu(pr);
|
||||
}
|
||||
ReviewMenuChoice::Open => return self.open_browser(pr, merge_strategy),
|
||||
ReviewMenuChoice::Open => return self.open_browser(pr),
|
||||
ReviewMenuChoice::Skip => {}
|
||||
ReviewMenuChoice::Merge => self.merge(pr, merge_strategy)?,
|
||||
ReviewMenuChoice::Merge => self.merge(pr)?,
|
||||
ReviewMenuChoice::ApproveAndMerge => {
|
||||
self.approve(pr)?;
|
||||
self.merge(pr, merge_strategy)?;
|
||||
self.merge(pr)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn merge(&self, pr: &PullRequest, merge_strategy: &Option<MergeStrategy>) -> eyre::Result<()> {
|
||||
self.backend.enable_auto_merge(pr, merge_strategy)?;
|
||||
fn merge(&self, pr: &PullRequest) -> eyre::Result<()> {
|
||||
self.backend.enable_auto_merge(pr);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl util::Cmd for Review {
|
||||
fn cmd() -> eyre::Result<clap::Command> {
|
||||
Ok(clap::Command::new("review")
|
||||
.arg(
|
||||
clap::Arg::new("review-requested")
|
||||
.long("review-requested")
|
||||
.default_value("@me")
|
||||
.help("which user or team to pull reviews from"),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::new("merge-strategy")
|
||||
.long("merge-strategy")
|
||||
.help(
|
||||
"when merging which merge strategy to use, possible values: [squash, merge]",
|
||||
),
|
||||
))
|
||||
Ok(clap::Command::new("review"))
|
||||
}
|
||||
|
||||
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
|
||||
let request_requested = args
|
||||
.get_one::<String>("review-requested")
|
||||
.map(|r| r.clone());
|
||||
|
||||
let squash = args
|
||||
.get_one::<String>("merge-strategy")
|
||||
.and_then(|s| match s.as_str() {
|
||||
"squash" => Some(MergeStrategy::Squash),
|
||||
"merge" => Some(MergeStrategy::MergeCommit),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
Self::default().run(request_requested, &squash)
|
||||
fn exec(_: &clap::ArgMatches) -> eyre::Result<()> {
|
||||
Self::default().run(Some("lunarway/squad-aura".into()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +194,7 @@ mod tests {
|
||||
backend.expect_present_prs().times(1).returning(|_| Ok(()));
|
||||
|
||||
let review = Review::new(std::sync::Arc::new(backend));
|
||||
let res = review.run(None, &None);
|
||||
let res = review.run(Some("kjuulh".into()));
|
||||
|
||||
assert_err::<ReviewErrors, _>(res)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ pub mod models;
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
use self::models::{MenuChoice, MergeStrategy, PullRequest, ReviewMenuChoice};
|
||||
use self::models::{MenuChoice, PullRequest, ReviewMenuChoice};
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::{automock, predicate::*};
|
||||
@ -16,11 +16,7 @@ pub trait ReviewBackend {
|
||||
fn approve(&self, pr: &PullRequest) -> eyre::Result<()>;
|
||||
fn pr_open_browser(&self, pr: &PullRequest) -> eyre::Result<()>;
|
||||
fn clear(&self) -> eyre::Result<()>;
|
||||
fn enable_auto_merge(
|
||||
&self,
|
||||
pr: &PullRequest,
|
||||
merge_strategy: &Option<MergeStrategy>,
|
||||
) -> eyre::Result<()>;
|
||||
fn enable_auto_merge(&self, pr: &PullRequest) -> eyre::Result<()>;
|
||||
fn present_pr(&self, pr: &PullRequest) -> eyre::Result<()>;
|
||||
}
|
||||
|
||||
@ -38,9 +34,11 @@ impl ReviewBackend for DefaultReviewBackend {
|
||||
"prs",
|
||||
"--state=open",
|
||||
"--review-requested",
|
||||
review_request.unwrap_or("@me".into()).as_str(),
|
||||
"@me",
|
||||
//review_request.unwrap().as_str(),
|
||||
"--label",
|
||||
"dependencies",
|
||||
//"--checks=pending",
|
||||
"--json",
|
||||
"repository,number,title",
|
||||
],
|
||||
@ -165,30 +163,19 @@ impl ReviewBackend for DefaultReviewBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn enable_auto_merge(
|
||||
&self,
|
||||
pr: &PullRequest,
|
||||
merge_strategy: &Option<MergeStrategy>,
|
||||
) -> eyre::Result<()> {
|
||||
let number = pr.number.to_string();
|
||||
let mut args = vec![
|
||||
"gh",
|
||||
"pr",
|
||||
"merge",
|
||||
number.as_str(),
|
||||
"--auto",
|
||||
"--repo",
|
||||
pr.repository.name.as_str(),
|
||||
];
|
||||
|
||||
if let Some(merge_strategy) = merge_strategy {
|
||||
match merge_strategy {
|
||||
MergeStrategy::Squash => args.push("--squash"),
|
||||
MergeStrategy::MergeCommit => args.push("--merge"),
|
||||
}
|
||||
}
|
||||
|
||||
util::shell::run(args.as_slice(), None)?;
|
||||
fn enable_auto_merge(&self, pr: &PullRequest) -> eyre::Result<()> {
|
||||
util::shell::run(
|
||||
&[
|
||||
"gh",
|
||||
"pr",
|
||||
"merge",
|
||||
pr.number.to_string().as_str(),
|
||||
"--auto",
|
||||
"--repo",
|
||||
pr.repository.name.as_str(),
|
||||
],
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -13,12 +13,6 @@ pub struct PullRequest {
|
||||
pub repository: Repository,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MergeStrategy {
|
||||
Squash,
|
||||
MergeCommit,
|
||||
}
|
||||
|
||||
pub enum MenuChoice {
|
||||
Exit,
|
||||
Begin,
|
||||
|
Reference in New Issue
Block a user