11use std:: path:: PathBuf ;
2- use std:: sync:: Arc ;
32
43use grhooks_config:: WebhookConfig ;
54use srtemplate:: SrTemplate ;
65
7- pub async fn execute_command < ' a > (
6+ pub async fn execute_command (
87 config : & WebhookConfig ,
98 event_type : & str ,
109 value : & serde_json:: Value ,
1110) -> std:: io:: Result < String > {
12- let ctx = Arc :: new ( SrTemplate :: with_delimiter ( "${{" , "}}" ) ) ;
11+ let ctx = SrTemplate :: with_delimiter ( "${{" , "}}" ) ;
1312 ctx. add_variable ( "event.type" , event_type) ;
14- crate :: process_value ( ctx. clone ( ) , "event" , value) ;
13+ crate :: process_value ( & ctx, "event" , value) ;
1514
1615 let ( shell, args) = if let Some ( shell) = config. shell . as_ref ( ) {
1716 let mut args = shell. clone ( ) ;
@@ -22,9 +21,9 @@ pub async fn execute_command<'a>(
2221 } ;
2322
2423 let output = if let Some ( script_path) = & config. script {
25- execute_script ( ctx. as_ref ( ) , script_path, & shell, & args) . await ?
24+ execute_script ( & ctx, script_path, & shell, & args) . await ?
2625 } else if let Some ( command) = config. command . as_deref ( ) {
27- execute_direct_command ( ctx. as_ref ( ) , command, & shell, & args) . await ?
26+ execute_direct_command ( & ctx, command, & shell, & args) . await ?
2827 } else {
2928 return Err ( std:: io:: Error :: new (
3029 std:: io:: ErrorKind :: Other ,
@@ -35,8 +34,8 @@ pub async fn execute_command<'a>(
3534 Ok ( output)
3635}
3736
38- async fn execute_direct_command < ' a > (
39- ctx : & SrTemplate < ' a > ,
37+ async fn execute_direct_command (
38+ ctx : & SrTemplate < ' _ > ,
4039 command : & str ,
4140 shell : & str ,
4241 shell_args : & [ String ] ,
@@ -55,11 +54,11 @@ async fn execute_direct_command<'a>(
5554 . output ( )
5655 . await ?;
5756
58- handle_command_output ( output, & rendered_cmd)
57+ handle_command_output ( & output, & rendered_cmd)
5958}
6059
61- async fn execute_script < ' a > (
62- ctx : & SrTemplate < ' a > ,
60+ async fn execute_script (
61+ ctx : & SrTemplate < ' _ > ,
6362 script_path : & PathBuf ,
6463 shell : & str ,
6564 shell_args : & [ String ] ,
@@ -93,10 +92,10 @@ async fn execute_script<'a>(
9392 . output ( )
9493 . await ?;
9594
96- handle_command_output ( output, & format ! ( "script: {temp_script:?}" ) )
95+ handle_command_output ( & output, & format ! ( "script: {temp_script:?}" ) )
9796}
9897
99- fn handle_command_output ( output : std:: process:: Output , context : & str ) -> std:: io:: Result < String > {
98+ fn handle_command_output ( output : & std:: process:: Output , context : & str ) -> std:: io:: Result < String > {
10099 if !output. status . success ( ) {
101100 let err_msg = format ! (
102101 "Command failed ({} - {}):\n STDERR: {}\n STDOUT: {}" ,
0 commit comments