Skip to content

Commit 937107d

Browse files
committed
Make reminders responder case insensitive
1 parent 8751f73 commit 937107d

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

app/responders/reminders_responder.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ def process_message(message)
1717

1818
human = "@#{user_login(context.sender)}" if human == "me"
1919

20-
unless targets.include?(human)
20+
unless targets.include?(human.downcase)
2121
respond("#{human} doesn't seem to be a reviewer or author for this submission.")
2222
return false
2323
end
2424

2525
schedule_at = target_time(size, unit)
2626

2727
if schedule_at
28-
if user_login(human) == user_login(context.sender)
28+
if user_login(human).downcase == user_login(context.sender).downcase
29+
human = "@#{user_login(context.sender)}"
2930
msg = ":wave: #{human}, please take a look at the state of the submission (this is an automated reminder)."
3031
AsyncMessageWorker.perform_at(schedule_at, serializable(locals), msg)
3132
else
32-
ReviewReminderWorker.perform_at(schedule_at, serializable(locals), human, authors_list.include?(human))
33+
ReviewReminderWorker.perform_at(schedule_at, serializable(locals), human, authors_list.include?(human.downcase))
3334
end
3435
respond("Reminder set for #{human} in #{size} #{unit}")
3536
else
@@ -38,16 +39,16 @@ def process_message(message)
3839
end
3940

4041
def targets
41-
(authors_list + reviewers_list + ["@#{user_login(context.sender)}"]).uniq
42+
(authors_list + reviewers_list + ["@#{user_login(context.sender).downcase}"]).uniq
4243
end
4344

4445
def reviewers_list
45-
@reviewers_list ||= reviewers_value.inject([]) {|re, value| re + read_value_from_body(value).split(",").map(&:strip)}
46+
@reviewers_list ||= reviewers_value.inject([]) {|re, value| re + read_value_from_body(value).split(",").map(&:strip).map(&:downcase)}
4647
@reviewers_list.compact.uniq
4748
end
4849

4950
def authors_list
50-
@authors_list ||= authors_value.inject([]) {|au, value| au + read_value_from_body(value).split(",").map(&:strip)}
51+
@authors_list ||= authors_value.inject([]) {|au, value| au + read_value_from_body(value).split(",").map(&:strip).map(&:downcase)}
5152
@authors_list.compact.uniq
5253
end
5354

spec/responders/reminders_responder_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@
5656
@responder.process_message(msg)
5757
end
5858

59+
it "should be case insensitive with the editor's GitHub handles" do
60+
msg = "@botsci remind @eDItoR21 in 5 weeks"
61+
@responder.match_data = @responder.event_regex.match(msg)
62+
in_five_weeks = Chronic.parse("in 5 weeks")
63+
expect(@responder).to receive(:target_time).with("5", "weeks").and_return(in_five_weeks)
64+
expected_msg = ":wave: @editor21, please take a look at the state of the submission (this is an automated reminder)."
65+
expect(AsyncMessageWorker).to receive(:perform_at).with(in_five_weeks, @responder.locals, expected_msg)
66+
expect(ReviewReminderWorker).to_not receive(:perform_at)
67+
expect(@responder).to receive(:respond).with("Reminder set for @editor21 in 5 weeks")
68+
69+
@responder.process_message(msg)
70+
end
71+
5972
it "should respond success message and schedule worker run for 'me'" do
6073
msg = "@botsci remind me in 15 days"
6174
@responder.match_data = @responder.event_regex.match(msg)
@@ -88,6 +101,26 @@
88101
expect(ReviewReminderWorker).to receive(:perform_at).with(in_four_days, @responder.locals, "@author", true)
89102
@responder.process_message(msg)
90103
end
104+
105+
it "should be case insensitive with the reviewers GitHub handles" do
106+
msg = "@botsci remind @ReVieWEr42 in 3 weeks"
107+
@responder.match_data = @responder.event_regex.match(msg)
108+
expect(ReviewReminderWorker).to receive(:perform_at)
109+
expect(@responder).to receive(:respond).with("Reminder set for @ReVieWEr42 in 3 weeks")
110+
111+
@responder.process_message(msg)
112+
end
113+
114+
it "should be case insensitive with the authors GitHub handles" do
115+
msg = "@botsci remind @AUTHor in 4 days"
116+
@responder.match_data = @responder.event_regex.match(msg)
117+
118+
in_four_days = Chronic.parse("in 4 days")
119+
expect(@responder).to receive(:target_time).with("4", "days").and_return(in_four_days)
120+
121+
expect(ReviewReminderWorker).to receive(:perform_at).with(in_four_days, @responder.locals, "@AUTHor", true)
122+
@responder.process_message(msg)
123+
end
91124
end
92125

93126
describe "configurable targets" do

0 commit comments

Comments
 (0)