Skip to content

Commit aea4015

Browse files
committed
Allow multiple commands in a single comment
1 parent eba703a commit aea4015

File tree

1 file changed

+33
-47
lines changed

1 file changed

+33
-47
lines changed

src/handlers.rs

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,18 @@ macro_rules! command_handlers {
122122
}
123123
}
124124

125-
// TODO: parse multiple commands and diff them
126-
let mut input = Input::new(&body, &ctx.username);
127-
let command = input.next();
128-
129-
if let Some(previous) = event.comment_from() {
130-
let mut prev_input = Input::new(&previous, &ctx.username);
131-
let prev_command = prev_input.next();
132-
if command == prev_command {
133-
log::info!(
134-
"skipping unmodified command: {:?} -> {:?}",
135-
prev_command,
136-
command
137-
);
138-
return;
139-
} else {
140-
log::debug!(
141-
"executing modified command: {:?} -> {:?}",
142-
prev_command,
143-
command
144-
);
145-
}
146-
}
147-
148-
let command = match command {
149-
Some(command) => command,
150-
None => return,
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()
151131
};
152132

133+
if commands.is_empty() {
134+
return;
135+
}
136+
153137
let config = match config {
154138
Ok(config) => config,
155139
Err(e @ ConfigurationError::Missing) => {
@@ -163,30 +147,32 @@ macro_rules! command_handlers {
163147
}
164148
};
165149

166-
match command {
167-
$(
168-
Command::$enum(Ok(command)) => {
169-
if let Some(config) = &config.$name {
170-
$name::handle_command(ctx, config, event, command)
171-
.await
172-
.unwrap_or_else(|err| errors.push(HandlerError::Other(err)));
173-
} else {
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+
}
166+
}
167+
Command::$enum(Err(err)) => {
174168
errors.push(HandlerError::Message(format!(
175-
"The feature `{}` is not enabled in this repository.\n\
176-
To enable it add its section in the `triagebot.toml` \
177-
in the root of the repository.",
178-
stringify!($name)
169+
"Parsing {} command in [comment]({}) failed: {}",
170+
stringify!($name),
171+
event.html_url().expect("has html url"),
172+
err
179173
)));
180-
}
174+
})*
181175
}
182-
Command::$enum(Err(err)) => {
183-
errors.push(HandlerError::Message(format!(
184-
"Parsing {} command in [comment]({}) failed: {}",
185-
stringify!($name),
186-
event.html_url().expect("has html url"),
187-
err
188-
)));
189-
})*
190176
}
191177
}
192178
}

0 commit comments

Comments
 (0)