Skip to content

Commit 6c30d9e

Browse files
committed
Implement command diffing for other commands
1 parent 846eb97 commit 6c30d9e

File tree

6 files changed

+84
-37
lines changed

6 files changed

+84
-37
lines changed

src/handlers/glacier.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ impl Handler for GlacierHandler {
3232
};
3333

3434
let mut input = Input::new(&body, &ctx.username);
35-
match input.parse_command() {
35+
let command = input.parse_command();
36+
37+
if let Some(previous) = event.comment_from() {
38+
let mut prev_input = Input::new(&previous, &ctx.username);
39+
let prev_command = prev_input.parse_command();
40+
if command == prev_command {
41+
return Ok(None);
42+
}
43+
}
44+
45+
match command {
3646
Command::Glacier(Ok(command)) => Ok(Some(command)),
3747
Command::Glacier(Err(err)) => {
3848
return Err(format!(

src/handlers/major_change.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,21 @@ impl Handler for MajorChangeHandler {
6363
// All other issue events are ignored
6464
return Ok(None);
6565
}
66-
Event::IssueComment(e) => {
67-
if e.action != github::IssueCommentAction::Created {
68-
return Ok(None);
69-
}
70-
}
66+
Event::IssueComment(e) => {}
7167
}
7268

7369
let mut input = Input::new(&body, &ctx.username);
74-
match input.parse_command() {
70+
let command = input.parse_command();
71+
72+
if let Some(previous) = event.comment_from() {
73+
let mut prev_input = Input::new(&previous, &ctx.username);
74+
let prev_command = prev_input.parse_command();
75+
if command == prev_command {
76+
return Ok(None);
77+
}
78+
}
79+
80+
match command {
7581
Command::Second(Ok(SecondCommand)) => Ok(Some(Invocation::Second)),
7682
_ => Ok(None),
7783
}
@@ -107,14 +113,6 @@ async fn handle_input(
107113
return Ok(());
108114
}
109115

110-
if !issue.labels().iter().any(|l| l.name == "major-change") {
111-
let cmnt = ErrorComment::new(
112-
&issue,
113-
"This is not a major change (it lacks the `major-change` label).",
114-
);
115-
cmnt.post(&ctx.github).await?;
116-
return Ok(());
117-
}
118116
let is_team_member =
119117
if let Err(_) | Ok(false) = event.user().is_team_member(&ctx.github).await {
120118
false

src/handlers/nominate.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,25 @@ impl Handler for NominateHandler {
3030
};
3131

3232
if let Event::Issue(e) = event {
33-
if e.action != github::IssuesAction::Opened {
34-
// skip events other than opening the issue to avoid retriggering commands in the
33+
if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
34+
// skip events other than opening or editing the issue to avoid retriggering commands in the
3535
// issue body
3636
return Ok(None);
3737
}
3838
}
3939

4040
let mut input = Input::new(&body, &ctx.username);
41-
match input.parse_command() {
41+
let command = input.parse_command();
42+
43+
if let Some(previous) = event.comment_from() {
44+
let mut prev_input = Input::new(&previous, &ctx.username);
45+
let prev_command = prev_input.parse_command();
46+
if command == prev_command {
47+
return Ok(None);
48+
}
49+
}
50+
51+
match command {
4252
Command::Nominate(Ok(command)) => Ok(Some(command)),
4353
Command::Nominate(Err(err)) => {
4454
return Err(format!(

src/handlers/ping.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,26 @@ impl Handler for PingHandler {
3333
return Ok(None);
3434
};
3535

36-
match event {
37-
Event::Issue(e) => {
38-
if e.action != github::IssuesAction::Opened {
39-
// skip events other than opening the issue to avoid retriggering commands in the
40-
// issue body
41-
return Ok(None);
42-
}
43-
}
44-
Event::IssueComment(e) => {
45-
// Especially on ping commands, which ping tons of folks, this
46-
// is quite noisy.
47-
if e.action != github::IssueCommentAction::Created {
48-
return Ok(None);
49-
}
36+
if let Event::Issue(e) = event {
37+
if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
38+
// skip events other than opening or editing the issue to avoid retriggering commands in the
39+
// issue body
40+
return Ok(None);
5041
}
5142
}
5243

5344
let mut input = Input::new(&body, &ctx.username);
54-
match input.parse_command() {
45+
let command = input.parse_command();
46+
47+
if let Some(previous) = event.comment_from() {
48+
let mut prev_input = Input::new(&previous, &ctx.username);
49+
let prev_command = prev_input.parse_command();
50+
if command == prev_command {
51+
return Ok(None);
52+
}
53+
}
54+
55+
match command {
5556
Command::Ping(Ok(command)) => Ok(Some(command)),
5657
Command::Ping(Err(err)) => {
5758
return Err(format!(

src/handlers/prioritize.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,27 @@ impl Handler for PrioritizeHandler {
2525
// not interested in other events
2626
return Ok(None);
2727
};
28+
29+
if let Event::Issue(e) = event {
30+
if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
31+
// skip events other than opening or editing the issue to avoid retriggering commands in the
32+
// issue body
33+
return Ok(None);
34+
}
35+
}
2836

2937
let mut input = Input::new(&body, &ctx.username);
30-
match input.parse_command() {
38+
let command = input.parse_command();
39+
40+
if let Some(previous) = event.comment_from() {
41+
let mut prev_input = Input::new(&previous, &ctx.username);
42+
let prev_command = prev_input.parse_command();
43+
if command == prev_command {
44+
return Ok(None);
45+
}
46+
}
47+
48+
match command {
3149
Command::Prioritize(Ok(PrioritizeCommand)) => Ok(Some(PrioritizeCommand)),
3250
_ => Ok(None),
3351
}

src/handlers/relabel.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,25 @@ impl Handler for RelabelHandler {
3838
};
3939

4040
if let Event::Issue(e) = event {
41-
if e.action != github::IssuesAction::Opened {
42-
// skip events other than opening the issue to avoid retriggering commands in the
41+
if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
42+
// skip events other than opening or editing the issue to avoid retriggering commands in the
4343
// issue body
4444
return Ok(None);
4545
}
4646
}
4747

4848
let mut input = Input::new(&body, &ctx.username);
49-
match input.parse_command() {
49+
let command = input.parse_command();
50+
51+
if let Some(previous) = event.comment_from() {
52+
let mut prev_input = Input::new(&previous, &ctx.username);
53+
let prev_command = prev_input.parse_command();
54+
if command == prev_command {
55+
return Ok(None);
56+
}
57+
}
58+
59+
match command {
5060
Command::Relabel(Ok(command)) => Ok(Some(command)),
5161
Command::Relabel(Err(err)) => {
5262
return Err(format!(

0 commit comments

Comments
 (0)