Skip to content

Commit 6ba5b76

Browse files
committed
fix tests
1 parent 4dd06ec commit 6ba5b76

File tree

3 files changed

+103
-106
lines changed

3 files changed

+103
-106
lines changed

src/cli/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use color_eyre::eyre::{self, WrapErr};
77
use crate::{
88
Repo,
99
commands::{
10-
cd::CdCommand, create::CreateCommand, list::ListCommand, pr_github::PrGithubCommand,
10+
cd::CdCommand,
11+
create::CreateCommand,
12+
list::ListCommand,
13+
pr_github::{PrGithubCommand, PrGithubOptions},
1114
rm::RemoveCommand,
1215
},
1316
};
@@ -97,7 +100,7 @@ pub fn run() -> color_eyre::Result<()> {
97100
command.execute(&repo)?;
98101
}
99102
Commands::Ls => {
100-
let command = ListCommand::default();
103+
let command = ListCommand;
101104
command.execute(&repo)?;
102105
}
103106
Commands::Cd(args) => {
@@ -110,16 +113,17 @@ pub fn run() -> color_eyre::Result<()> {
110113
}
111114
Commands::PrGithub(args) => {
112115
let worktree_name = resolve_worktree_name(args.name, &repo)?;
113-
let mut command = PrGithubCommand::new(
114-
worktree_name,
115-
!args.no_push,
116-
args.draft,
117-
args.fill,
118-
args.web,
119-
args.remote,
120-
args.reviewers,
121-
args.extra,
122-
);
116+
let options = PrGithubOptions {
117+
name: worktree_name,
118+
push: !args.no_push,
119+
draft: args.draft,
120+
fill: args.fill,
121+
web: args.web,
122+
remote: args.remote,
123+
reviewers: args.reviewers,
124+
extra_args: args.extra,
125+
};
126+
let mut command = PrGithubCommand::new(options);
123127
command.execute(&repo)?;
124128
}
125129
}

src/commands/cd/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ impl CdCommand {
6161
}
6262

6363
pub(crate) fn shell_command() -> (String, Vec<String>) {
64-
if let Ok(override_shell) = std::env::var(SHELL_OVERRIDE_ENV) {
65-
if !override_shell.trim().is_empty() {
66-
return (override_shell, Vec::new());
67-
}
64+
if let Ok(override_shell) = std::env::var(SHELL_OVERRIDE_ENV)
65+
&& !override_shell.trim().is_empty()
66+
{
67+
return (override_shell, Vec::new());
6868
}
6969

70-
if let Ok(shell) = std::env::var("SHELL") {
71-
if !shell.trim().is_empty() {
72-
return (shell, vec!["-i".into()]);
73-
}
70+
if let Ok(shell) = std::env::var("SHELL")
71+
&& !shell.trim().is_empty()
72+
{
73+
return (shell, vec!["-i".into()]);
7474
}
7575

7676
("/bin/sh".into(), vec!["-i".into()])

src/commands/pr_github/mod.rs

Lines changed: 79 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ use owo_colors::{OwoColorize, Stream};
99

1010
use crate::Repo;
1111

12+
#[derive(Debug)]
13+
pub struct PrGithubOptions {
14+
pub name: String,
15+
pub push: bool,
16+
pub draft: bool,
17+
pub fill: bool,
18+
pub web: bool,
19+
pub remote: String,
20+
pub reviewers: Vec<String>,
21+
pub extra_args: Vec<String>,
22+
}
23+
1224
#[derive(Debug)]
1325
pub struct PrGithubCommand<R = SystemCommandRunner> {
1426
name: String,
@@ -23,17 +35,17 @@ pub struct PrGithubCommand<R = SystemCommandRunner> {
2335
}
2436

2537
impl PrGithubCommand {
26-
pub fn new(
27-
name: String,
28-
push: bool,
29-
draft: bool,
30-
fill: bool,
31-
web: bool,
32-
remote: String,
33-
reviewers: Vec<String>,
34-
extra_args: Vec<String>,
35-
) -> Self {
36-
Self::with_runner(
38+
pub fn new(options: PrGithubOptions) -> Self {
39+
Self::with_runner(options, SystemCommandRunner)
40+
}
41+
}
42+
43+
impl<R> PrGithubCommand<R>
44+
where
45+
R: CommandRunner,
46+
{
47+
pub fn with_runner(options: PrGithubOptions, runner: R) -> Self {
48+
let PrGithubOptions {
3749
name,
3850
push,
3951
draft,
@@ -42,26 +54,7 @@ impl PrGithubCommand {
4254
remote,
4355
reviewers,
4456
extra_args,
45-
SystemCommandRunner,
46-
)
47-
}
48-
}
49-
50-
impl<R> PrGithubCommand<R>
51-
where
52-
R: CommandRunner,
53-
{
54-
pub fn with_runner(
55-
name: String,
56-
push: bool,
57-
draft: bool,
58-
fill: bool,
59-
web: bool,
60-
remote: String,
61-
reviewers: Vec<String>,
62-
extra_args: Vec<String>,
63-
runner: R,
64-
) -> Self {
57+
} = options;
6558
Self {
6659
name,
6760
push,
@@ -545,17 +538,17 @@ mod tests {
545538
status_code: Some(0),
546539
}));
547540

548-
let mut command = PrGithubCommand::with_runner(
549-
"feature/test".into(),
550-
true,
551-
false,
552-
true,
553-
false,
554-
"origin".into(),
555-
vec!["octocat".into()],
556-
vec!["--label".into(), "ready".into()],
557-
runner,
558-
);
541+
let options = PrGithubOptions {
542+
name: "feature/test".into(),
543+
push: true,
544+
draft: false,
545+
fill: true,
546+
web: false,
547+
remote: "origin".into(),
548+
reviewers: vec!["octocat".into()],
549+
extra_args: vec!["--label".into(), "ready".into()],
550+
};
551+
let mut command = PrGithubCommand::with_runner(options, runner);
559552

560553
command.execute(&repo)?;
561554

@@ -633,17 +626,17 @@ mod tests {
633626
status_code: Some(0),
634627
}));
635628

636-
let mut command = PrGithubCommand::with_runner(
637-
"feature/test".into(),
638-
false,
639-
true,
640-
true,
641-
true,
642-
"origin".into(),
643-
Vec::new(),
644-
Vec::new(),
645-
runner,
646-
);
629+
let options = PrGithubOptions {
630+
name: "feature/test".into(),
631+
push: false,
632+
draft: true,
633+
fill: true,
634+
web: true,
635+
remote: "origin".into(),
636+
reviewers: Vec::new(),
637+
extra_args: Vec::new(),
638+
};
639+
let mut command = PrGithubCommand::with_runner(options, runner);
647640

648641
command.execute(&repo)?;
649642

@@ -679,17 +672,17 @@ mod tests {
679672
init_git_repo(&repo_dir)?;
680673
let repo = Repo::discover_from(repo_dir.path())?;
681674

682-
let mut command = PrGithubCommand::with_runner(
683-
"missing".into(),
684-
true,
685-
false,
686-
false,
687-
false,
688-
"origin".into(),
689-
Vec::new(),
690-
Vec::new(),
691-
MockCommandRunner::default(),
692-
);
675+
let options = PrGithubOptions {
676+
name: "missing".into(),
677+
push: true,
678+
draft: false,
679+
fill: false,
680+
web: false,
681+
remote: "origin".into(),
682+
reviewers: Vec::new(),
683+
extra_args: Vec::new(),
684+
};
685+
let mut command = PrGithubCommand::with_runner(options, MockCommandRunner::default());
693686

694687
let err = command.execute(&repo).unwrap_err();
695688
assert!(err.to_string().contains("does not exist"));
@@ -712,17 +705,17 @@ mod tests {
712705
status_code: Some(128),
713706
}));
714707

715-
let mut command = PrGithubCommand::with_runner(
716-
"feature/test".into(),
717-
true,
718-
false,
719-
false,
720-
false,
721-
"origin".into(),
722-
Vec::new(),
723-
Vec::new(),
724-
runner,
725-
);
708+
let options = PrGithubOptions {
709+
name: "feature/test".into(),
710+
push: true,
711+
draft: false,
712+
fill: false,
713+
web: false,
714+
remote: "origin".into(),
715+
reviewers: Vec::new(),
716+
extra_args: Vec::new(),
717+
};
718+
let mut command = PrGithubCommand::with_runner(options, runner);
726719

727720
let err = command.execute(&repo).unwrap_err();
728721
assert!(err.to_string().contains("git rev-parse"));
@@ -759,17 +752,17 @@ mod tests {
759752
}),
760753
]);
761754

762-
let mut command = PrGithubCommand::with_runner(
763-
"feature/test".into(),
764-
true,
765-
false,
766-
false,
767-
false,
768-
"origin".into(),
769-
Vec::new(),
770-
Vec::new(),
771-
runner,
772-
);
755+
let options = PrGithubOptions {
756+
name: "feature/test".into(),
757+
push: true,
758+
draft: false,
759+
fill: false,
760+
web: false,
761+
remote: "origin".into(),
762+
reviewers: Vec::new(),
763+
extra_args: Vec::new(),
764+
};
765+
let mut command = PrGithubCommand::with_runner(options, runner);
773766

774767
command.execute(&repo)?;
775768

0 commit comments

Comments
 (0)