1- use crate :: actions:: experiments:: ExperimentError ;
2- use crate :: config:: Config ;
3- use crate :: db:: { Database , QueryUtils } ;
1+ use crate :: actions:: { experiments:: ExperimentError , Action , ActionsCtx } ;
2+ use crate :: db:: QueryUtils ;
43use crate :: experiments:: { CapLints , CrateSelect , Experiment , GitHubIssue , Mode , Status } ;
54use crate :: prelude:: * ;
65use crate :: toolchain:: Toolchain ;
@@ -33,21 +32,23 @@ impl CreateExperiment {
3332 ignore_blacklist : false ,
3433 }
3534 }
35+ }
3636
37- pub fn apply ( self , db : & Database , config : & Config ) -> Fallible < ( ) > {
37+ impl Action for CreateExperiment {
38+ fn apply ( self , ctx : & ActionsCtx ) -> Fallible < ( ) > {
3839 // Ensure no duplicate experiments are created
39- if Experiment :: exists ( db, & self . name ) ? {
40- return Err ( ExperimentError :: AlreadyExists ( self . name ) . into ( ) ) ;
40+ if Experiment :: exists ( & ctx . db , & self . name ) ? {
41+ return Err ( ExperimentError :: AlreadyExists ( self . name . clone ( ) ) . into ( ) ) ;
4142 }
4243
4344 // Ensure no experiment with duplicate toolchains is created
4445 if self . toolchains [ 0 ] == self . toolchains [ 1 ] {
4546 return Err ( ExperimentError :: DuplicateToolchains . into ( ) ) ;
4647 }
4748
48- let crates = crate :: crates:: lists:: get_crates ( self . crates , db, config) ?;
49+ let crates = crate :: crates:: lists:: get_crates ( self . crates , & ctx . db , & ctx . config ) ?;
4950
50- db. transaction ( |transaction| {
51+ ctx . db . transaction ( |transaction| {
5152 transaction. execute (
5253 "INSERT INTO experiments \
5354 (name, mode, cap_lints, toolchain_start, toolchain_end, priority, created_at, \
@@ -70,7 +71,7 @@ impl CreateExperiment {
7071 ) ?;
7172
7273 for krate in & crates {
73- let skipped = !self . ignore_blacklist && config. should_skip ( krate) ;
74+ let skipped = !self . ignore_blacklist && ctx . config . should_skip ( krate) ;
7475 transaction. execute (
7576 "INSERT INTO experiment_crates (experiment, crate, skipped) VALUES (?1, ?2, ?3);" ,
7677 & [ & self . name , & :: serde_json:: to_string ( & krate) ?, & skipped] ,
@@ -87,7 +88,7 @@ impl CreateExperiment {
8788#[ cfg( test) ]
8889mod tests {
8990 use super :: CreateExperiment ;
90- use crate :: actions:: ExperimentError ;
91+ use crate :: actions:: { Action , ActionsCtx , ExperimentError } ;
9192 use crate :: config:: { Config , CrateConfig } ;
9293 use crate :: crates:: Crate ;
9394 use crate :: db:: { Database , QueryUtils } ;
@@ -98,6 +99,7 @@ mod tests {
9899 fn test_creation ( ) {
99100 let db = Database :: temp ( ) . unwrap ( ) ;
100101 let config = Config :: default ( ) ;
102+ let ctx = ActionsCtx :: new ( & db, & config) ;
101103
102104 crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
103105
@@ -118,7 +120,7 @@ mod tests {
118120 } ) ,
119121 ignore_blacklist : true ,
120122 }
121- . apply ( & db , & config )
123+ . apply ( & ctx )
122124 . unwrap ( ) ;
123125
124126 let ex = Experiment :: get ( & db, "foo" ) . unwrap ( ) . unwrap ( ) ;
@@ -182,22 +184,23 @@ mod tests {
182184 broken : false ,
183185 } ,
184186 ) ;
187+ let ctx = ActionsCtx :: new ( & db, & config) ;
185188
186189 crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
187190
188191 CreateExperiment {
189192 ignore_blacklist : false ,
190193 ..CreateExperiment :: dummy ( "foo" )
191194 }
192- . apply ( & db , & config )
195+ . apply ( & ctx )
193196 . unwrap ( ) ;
194197 assert ! ( is_skipped( & db, "foo" , "build-pass" ) ) ;
195198
196199 CreateExperiment {
197200 ignore_blacklist : true ,
198201 ..CreateExperiment :: dummy ( "bar" )
199202 }
200- . apply ( & db , & config )
203+ . apply ( & ctx )
201204 . unwrap ( ) ;
202205 assert ! ( !is_skipped( & db, "bar" , "build-pass" ) ) ;
203206 }
@@ -206,6 +209,7 @@ mod tests {
206209 fn test_duplicate_toolchains ( ) {
207210 let db = Database :: temp ( ) . unwrap ( ) ;
208211 let config = Config :: default ( ) ;
212+ let ctx = ActionsCtx :: new ( & db, & config) ;
209213
210214 crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
211215
@@ -220,7 +224,7 @@ mod tests {
220224 github_issue : None ,
221225 ignore_blacklist : false ,
222226 }
223- . apply ( & db , & config )
227+ . apply ( & ctx )
224228 . unwrap_err ( ) ;
225229
226230 assert_eq ! (
@@ -233,6 +237,7 @@ mod tests {
233237 fn test_duplicate_name ( ) {
234238 let db = Database :: temp ( ) . unwrap ( ) ;
235239 let config = Config :: default ( ) ;
240+ let ctx = ActionsCtx :: new ( & db, & config) ;
236241
237242 crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
238243
@@ -247,7 +252,7 @@ mod tests {
247252 github_issue : None ,
248253 ignore_blacklist : false ,
249254 }
250- . apply ( & db , & config )
255+ . apply ( & ctx )
251256 . unwrap ( ) ;
252257
253258 // While the second one fails
@@ -261,7 +266,7 @@ mod tests {
261266 github_issue : None ,
262267 ignore_blacklist : false ,
263268 }
264- . apply ( & db , & config )
269+ . apply ( & ctx )
265270 . unwrap_err ( ) ;
266271
267272 assert_eq ! (
0 commit comments