1
1
use std:: path:: PathBuf ;
2
- use std:: sync:: Arc ;
3
2
4
3
use grhooks_config:: WebhookConfig ;
5
4
use srtemplate:: SrTemplate ;
6
5
7
- pub async fn execute_command < ' a > (
6
+ pub async fn execute_command (
8
7
config : & WebhookConfig ,
9
8
event_type : & str ,
10
9
value : & serde_json:: Value ,
11
10
) -> std:: io:: Result < String > {
12
- let ctx = Arc :: new ( SrTemplate :: with_delimiter ( "${{" , "}}" ) ) ;
11
+ let ctx = SrTemplate :: with_delimiter ( "${{" , "}}" ) ;
13
12
ctx. add_variable ( "event.type" , event_type) ;
14
- crate :: process_value ( ctx. clone ( ) , "event" , value) ;
13
+ crate :: process_value ( & ctx, "event" , value) ;
15
14
16
15
let ( shell, args) = if let Some ( shell) = config. shell . as_ref ( ) {
17
16
let mut args = shell. clone ( ) ;
@@ -22,9 +21,9 @@ pub async fn execute_command<'a>(
22
21
} ;
23
22
24
23
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 ?
26
25
} 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 ?
28
27
} else {
29
28
return Err ( std:: io:: Error :: new (
30
29
std:: io:: ErrorKind :: Other ,
@@ -35,8 +34,8 @@ pub async fn execute_command<'a>(
35
34
Ok ( output)
36
35
}
37
36
38
- async fn execute_direct_command < ' a > (
39
- ctx : & SrTemplate < ' a > ,
37
+ async fn execute_direct_command (
38
+ ctx : & SrTemplate < ' _ > ,
40
39
command : & str ,
41
40
shell : & str ,
42
41
shell_args : & [ String ] ,
@@ -55,11 +54,11 @@ async fn execute_direct_command<'a>(
55
54
. output ( )
56
55
. await ?;
57
56
58
- handle_command_output ( output, & rendered_cmd)
57
+ handle_command_output ( & output, & rendered_cmd)
59
58
}
60
59
61
- async fn execute_script < ' a > (
62
- ctx : & SrTemplate < ' a > ,
60
+ async fn execute_script (
61
+ ctx : & SrTemplate < ' _ > ,
63
62
script_path : & PathBuf ,
64
63
shell : & str ,
65
64
shell_args : & [ String ] ,
@@ -93,10 +92,10 @@ async fn execute_script<'a>(
93
92
. output ( )
94
93
. await ?;
95
94
96
- handle_command_output ( output, & format ! ( "script: {temp_script:?}" ) )
95
+ handle_command_output ( & output, & format ! ( "script: {temp_script:?}" ) )
97
96
}
98
97
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 > {
100
99
if !output. status . success ( ) {
101
100
let err_msg = format ! (
102
101
"Command failed ({} - {}):\n STDERR: {}\n STDOUT: {}" ,
0 commit comments