@@ -35,16 +35,16 @@ mod prioritize;
35
35
mod relabel;
36
36
mod rustc_commits;
37
37
38
- // TODO: Return multiple handler errors ?
39
- pub async fn handle ( ctx : & Context , event : & Event ) -> Result < ( ) , HandlerError > {
38
+ pub async fn handle ( ctx : & Context , event : & Event ) -> Vec < HandlerError > {
40
39
let config = config:: get ( & ctx. github , event. repo_name ( ) ) . await ;
40
+ let mut errors = Vec :: new ( ) ;
41
41
42
42
if let ( Ok ( config) , Event :: Issue ( event) ) = ( config. as_ref ( ) , event) {
43
- handle_issue ( ctx, event, config) . await ? ;
43
+ handle_issue ( ctx, event, config, & mut errors ) . await ;
44
44
}
45
45
46
46
if let Some ( body) = event. comment_body ( ) {
47
- handle_command ( ctx, event, & config, body) . await ? ;
47
+ handle_command ( ctx, event, & config, body, & mut errors ) . await ;
48
48
}
49
49
50
50
if let Err ( e) = notification:: handle ( ctx, event) . await {
@@ -63,28 +63,34 @@ pub async fn handle(ctx: &Context, event: &Event) -> Result<(), HandlerError> {
63
63
) ;
64
64
}
65
65
66
- Ok ( ( ) )
66
+ errors
67
67
}
68
68
69
69
macro_rules! issue_handlers {
70
70
( $( $name: ident, ) * ) => {
71
- async fn handle_issue( ctx: & Context , event: & IssuesEvent , config: & Arc <Config >) -> Result <( ) , HandlerError > {
71
+ async fn handle_issue(
72
+ ctx: & Context ,
73
+ event: & IssuesEvent ,
74
+ config: & Arc <Config >,
75
+ errors: & mut Vec <HandlerError >,
76
+ ) {
72
77
$(
73
- if let Some ( input) = $name:: parse_input(
74
- ctx, event, config. $name. as_ref( ) ,
75
- ) . map_err( HandlerError :: Message ) ? {
76
- if let Some ( config) = & config. $name {
77
- $name:: handle_input( ctx, config, event, input) . await . map_err( HandlerError :: Other ) ?;
78
- } else {
79
- return Err ( HandlerError :: Message ( format!(
80
- "The feature `{}` is not enabled in this repository.\n \
81
- To enable it add its section in the `triagebot.toml` \
82
- in the root of the repository.",
83
- stringify!( $name)
84
- ) ) ) ;
78
+ match $name:: parse_input( ctx, event, config. $name. as_ref( ) ) {
79
+ Err ( err) => errors. push( HandlerError :: Message ( err) ) ,
80
+ Ok ( Some ( input) ) => {
81
+ if let Some ( config) = & config. $name {
82
+ $name:: handle_input( ctx, config, event, input) . await . unwrap_or_else( |err| errors. push( HandlerError :: Other ( err) ) ) ;
83
+ } else {
84
+ errors. push( HandlerError :: Message ( format!(
85
+ "The feature `{}` is not enabled in this repository.\n \
86
+ To enable it add its section in the `triagebot.toml` \
87
+ in the root of the repository.",
88
+ stringify!( $name)
89
+ ) ) ) ;
90
+ }
85
91
}
92
+ Ok ( None ) => { }
86
93
} ) *
87
- Ok ( ( ) )
88
94
}
89
95
}
90
96
}
@@ -101,72 +107,73 @@ issue_handlers! {
101
107
102
108
macro_rules! command_handlers {
103
109
( $( $name: ident: $enum: ident, ) * ) => {
104
- async fn handle_command( ctx: & Context , event: & Event , config: & Result <Arc <Config >, ConfigurationError >, body: & str ) -> Result <( ) , HandlerError > {
110
+ async fn handle_command(
111
+ ctx: & Context ,
112
+ event: & Event ,
113
+ config: & Result <Arc <Config >, ConfigurationError >,
114
+ body: & str ,
115
+ errors: & mut Vec <HandlerError >,
116
+ ) {
105
117
if let Event :: Issue ( e) = event {
106
118
if !matches!( e. action, IssuesAction :: Opened | IssuesAction :: Edited ) {
107
119
// no change in issue's body for these events, so skip
108
120
log:: debug!( "skipping event, issue was {:?}" , e. action) ;
109
- return Ok ( ( ) ) ;
121
+ return ;
110
122
}
111
123
}
112
124
113
- // TODO: parse multiple commands and diff them
114
- let mut input = Input :: new( & body, & ctx. username) ;
115
- let command = input. parse_command( ) ;
116
-
117
- if let Some ( previous) = event. comment_from( ) {
118
- let mut prev_input = Input :: new( & previous, & ctx. username) ;
119
- let prev_command = prev_input. parse_command( ) ;
120
- if command == prev_command {
121
- log:: info!( "skipping unmodified command: {:?} -> {:?}" , prev_command, command) ;
122
- return Ok ( ( ) ) ;
123
- } else {
124
- log:: debug!( "executing modified command: {:?} -> {:?}" , prev_command, command) ;
125
- }
126
- }
125
+ let input = Input :: new( & body, & ctx. username) ;
126
+ let commands = if let Some ( previous) = event. comment_from( ) {
127
+ let prev_commands = Input :: new( & previous, & ctx. username) . collect:: <Vec <_>>( ) ;
128
+ input. filter( |cmd| !prev_commands. contains( cmd) ) . collect:: <Vec <_>>( )
129
+ } else {
130
+ input. collect( )
131
+ } ;
127
132
128
- if command == Command :: None {
129
- return Ok ( ( ) ) ;
133
+ if commands . is_empty ( ) {
134
+ return ;
130
135
}
131
136
132
137
let config = match config {
133
138
Ok ( config) => config,
134
139
Err ( e @ ConfigurationError :: Missing ) => {
135
- return Err ( HandlerError :: Message ( e. to_string( ) ) ) ;
140
+ return errors . push ( HandlerError :: Message ( e. to_string( ) ) ) ;
136
141
}
137
142
Err ( e @ ConfigurationError :: Toml ( _) ) => {
138
- return Err ( HandlerError :: Message ( e. to_string( ) ) ) ;
143
+ return errors . push ( HandlerError :: Message ( e. to_string( ) ) ) ;
139
144
}
140
145
Err ( e @ ConfigurationError :: Http ( _) ) => {
141
- return Err ( HandlerError :: Other ( e. clone( ) . into( ) ) ) ;
146
+ return errors . push ( HandlerError :: Other ( e. clone( ) . into( ) ) ) ;
142
147
}
143
148
} ;
144
149
145
- match command {
146
- $(
147
- Command :: $enum( Ok ( command) ) => {
148
- if let Some ( config) = & config. $name {
149
- $name:: handle_command( ctx, config, event, command) . await . map_err( HandlerError :: Other ) ?;
150
- } else {
151
- return Err ( HandlerError :: Message ( format!(
152
- "The feature `{}` is not enabled in this repository.\n \
153
- To enable it add its section in the `triagebot.toml` \
154
- in the root of the repository.",
155
- stringify!( $name)
156
- ) ) ) ;
150
+ for command in commands {
151
+ match command {
152
+ $(
153
+ Command :: $enum( Ok ( command) ) => {
154
+ if let Some ( config) = & config. $name {
155
+ $name:: handle_command( ctx, config, event, command)
156
+ . await
157
+ . unwrap_or_else( |err| errors. push( HandlerError :: Other ( err) ) ) ;
158
+ } else {
159
+ errors. push( HandlerError :: Message ( format!(
160
+ "The feature `{}` is not enabled in this repository.\n \
161
+ To enable it add its section in the `triagebot.toml` \
162
+ in the root of the repository.",
163
+ stringify!( $name)
164
+ ) ) ) ;
165
+ }
157
166
}
167
+ Command :: $enum( Err ( err) ) => {
168
+ errors. push( HandlerError :: Message ( format!(
169
+ "Parsing {} command in [comment]({}) failed: {}" ,
170
+ stringify!( $name) ,
171
+ event. html_url( ) . expect( "has html url" ) ,
172
+ err
173
+ ) ) ) ;
174
+ } ) *
158
175
}
159
- Command :: $enum( Err ( err) ) => {
160
- return Err ( HandlerError :: Message ( format!(
161
- "Parsing {} command in [comment]({}) failed: {}" ,
162
- stringify!( $name) ,
163
- event. html_url( ) . expect( "has html url" ) ,
164
- err
165
- ) ) ) ;
166
- } ) *
167
- Command :: None => unreachable!( ) ,
168
176
}
169
- Ok ( ( ) )
170
177
}
171
178
}
172
179
}
0 commit comments