@@ -9,6 +9,18 @@ use owo_colors::{OwoColorize, Stream};
99
1010use 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 ) ]
1325pub struct PrGithubCommand < R = SystemCommandRunner > {
1426 name : String ,
@@ -23,17 +35,17 @@ pub struct PrGithubCommand<R = SystemCommandRunner> {
2335}
2436
2537impl 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