66use std:: collections:: BTreeMap ;
77
88use aksh_gha_protocol:: azdo:: {
9- AgentJobRequestMessage , EndpointAuthorization , MaskHint , MaskType ,
10- PipelineContextData , ServiceEndpoint , TaskResources , TaskStep ,
11- TimelineReference , VariableValue ,
9+ AgentJobRequestMessage , EndpointAuthorization , MaskHint , MaskType , PipelineContextData ,
10+ ServiceEndpoint , TaskResources , TaskStep , TimelineReference , VariableValue ,
1211} ;
1312
14- use crate :: JobPlan ;
1513use crate :: eval:: { build_context, resolve_map, resolve_string} ;
14+ use crate :: JobPlan ;
1615use aksh_gha_expressions:: Context ;
1716use serde_json:: Value ;
1817
@@ -67,7 +66,9 @@ pub fn build_agent_job_message(
6766 variables. insert ( k. clone ( ) , VariableValue :: new ( v) ) ;
6867 }
6968 for ( k, v) in global_env {
70- variables. entry ( k. clone ( ) ) . or_insert_with ( || VariableValue :: new ( v) ) ;
69+ variables
70+ . entry ( k. clone ( ) )
71+ . or_insert_with ( || VariableValue :: new ( v) ) ;
7172 }
7273 for ( k, v) in vars {
7374 variables. insert ( k. clone ( ) , VariableValue :: new ( v) ) ;
@@ -90,8 +91,7 @@ pub fn build_agent_job_message(
9091 . collect ( ) ;
9192
9293 // Service endpoints (SystemVssConnection)
93- let mut endpoints = Vec :: new ( ) ;
94- endpoints. push ( ServiceEndpoint {
94+ let endpoints = vec ! [ ServiceEndpoint {
9595 data: BTreeMap :: new( ) ,
9696 name: "SystemVssConnection" . to_owned( ) ,
9797 endpoint_type: Some ( "azdoserver" . to_owned( ) ) ,
@@ -108,7 +108,7 @@ pub fn build_agent_job_message(
108108 ) ] ) ,
109109 is_shared: Some ( false ) ,
110110 service_owner: Some ( "github" . to_owned( ) ) ,
111- } ) ;
111+ } ] ;
112112
113113 let resources = TaskResources {
114114 endpoints,
@@ -153,10 +153,7 @@ pub fn build_agent_job_message(
153153 "needs" . to_owned ( ) ,
154154 PipelineContextData :: Dict ( BTreeMap :: new ( ) ) ,
155155 ) ;
156- context_data. insert (
157- "strategy" . to_owned ( ) ,
158- to_context_data ( & strategy_value) ,
159- ) ;
156+ context_data. insert ( "strategy" . to_owned ( ) , to_context_data ( & strategy_value) ) ;
160157
161158 // Actions download info
162159 let actions_download_info = BTreeMap :: new ( ) ;
@@ -180,7 +177,7 @@ pub fn build_agent_job_message(
180177}
181178
182179/// Build a `TaskStep` from a `StepPlan`.
183- fn build_task_step ( step : & crate :: StepPlan , index : usize , context : & Context ) -> TaskStep {
180+ fn build_task_step ( step : & crate :: StepPlan , _index : usize , context : & Context ) -> TaskStep {
184181 let step_id = uuid:: Uuid :: new_v4 ( ) ;
185182
186183 // Resolve expressions in env and with
@@ -189,7 +186,8 @@ fn build_task_step(step: &crate::StepPlan, index: usize, context: &Context) -> T
189186 . with
190187 . iter ( )
191188 . map ( |( k, v) | {
192- let resolved = resolve_string ( & v. to_string ( ) , context) . unwrap_or_else ( |_| v. to_string ( ) ) ;
189+ let resolved =
190+ resolve_string ( & v. to_string ( ) , context) . unwrap_or_else ( |_| v. to_string ( ) ) ;
193191 ( k. clone ( ) , resolved)
194192 } )
195193 . collect ( ) ;
@@ -209,14 +207,15 @@ fn build_task_step(step: &crate::StepPlan, index: usize, context: &Context) -> T
209207 display_name : step. name . clone ( ) ,
210208 condition,
211209 script : run,
212- reference : step. uses . as_ref ( ) . map ( |uses| {
213- aksh_gha_protocol:: azdo:: TaskReference {
210+ reference : step
211+ . uses
212+ . as_ref ( )
213+ . map ( |uses| aksh_gha_protocol:: azdo:: TaskReference {
214214 id : None ,
215215 name : Some ( uses. clone ( ) ) ,
216216 version : None ,
217217 reference_type : None ,
218- }
219- } ) ,
218+ } ) ,
220219 inputs : with,
221220 env,
222221 continue_on_error : None ,
@@ -272,13 +271,23 @@ jobs:
272271 "sha" : "abc123"
273272 } ) ;
274273
275- let msg = build_agent_job_message ( plan, & github, & BTreeMap :: new ( ) , & BTreeMap :: new ( ) , & BTreeMap :: new ( ) )
276- . unwrap ( ) ;
274+ let msg = build_agent_job_message (
275+ plan,
276+ & github,
277+ & BTreeMap :: new ( ) ,
278+ & BTreeMap :: new ( ) ,
279+ & BTreeMap :: new ( ) ,
280+ )
281+ . unwrap ( ) ;
277282
278283 assert ! ( !msg. steps. is_empty( ) ) ;
279284 assert ! ( msg. timeline. id != uuid:: Uuid :: nil( ) ) ;
280285 assert ! ( msg. job_id != uuid:: Uuid :: nil( ) ) ;
281- assert ! ( msg. resources. endpoints. iter( ) . any( |e| e. name == "SystemVssConnection" ) ) ;
286+ assert ! ( msg
287+ . resources
288+ . endpoints
289+ . iter( )
290+ . any( |e| e. name == "SystemVssConnection" ) ) ;
282291 }
283292
284293 #[ test]
@@ -299,8 +308,14 @@ jobs:
299308 assert_eq ! ( plans. len( ) , 2 ) ;
300309
301310 let github = serde_json:: json!( { "event_name" : "push" } ) ;
302- let msg = build_agent_job_message ( & plans[ 0 ] , & github, & BTreeMap :: new ( ) , & BTreeMap :: new ( ) , & BTreeMap :: new ( ) )
303- . unwrap ( ) ;
311+ let msg = build_agent_job_message (
312+ & plans[ 0 ] ,
313+ & github,
314+ & BTreeMap :: new ( ) ,
315+ & BTreeMap :: new ( ) ,
316+ & BTreeMap :: new ( ) ,
317+ )
318+ . unwrap ( ) ;
304319
305320 // Matrix should be in context data
306321 assert ! ( msg. context_data. contains_key( "matrix" ) ) ;
@@ -323,8 +338,14 @@ jobs:
323338 secrets. insert ( "MY_SECRET" . to_owned ( ) , "s3cr3t" . to_owned ( ) ) ;
324339
325340 let github = serde_json:: json!( { "event_name" : "push" } ) ;
326- let msg = build_agent_job_message ( & plans[ 0 ] , & github, & BTreeMap :: new ( ) , & secrets, & BTreeMap :: new ( ) )
327- . unwrap ( ) ;
341+ let msg = build_agent_job_message (
342+ & plans[ 0 ] ,
343+ & github,
344+ & BTreeMap :: new ( ) ,
345+ & secrets,
346+ & BTreeMap :: new ( ) ,
347+ )
348+ . unwrap ( ) ;
328349
329350 assert ! ( !msg. mask_hints. is_empty( ) ) ;
330351 assert_eq ! ( msg. mask_hints[ 0 ] . value, "s3cr3t" ) ;
0 commit comments