Skip to content

Commit

Permalink
Fix bug causing when am I on call to error out.
Browse files Browse the repository at this point in the history
This was happening if the person is not on any schedule.

Fixes #51
  • Loading branch information
Karl-Aksel Puulmann committed Feb 3, 2017
1 parent fd51d6d commit 736a89c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/pagerbot/action_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ def lookup_person(query, event_data)
# person goes on any on call.
if query[:schedule] == 'call'
next_oncall = @pagerduty.next_oncall(person.id, nil)
schedule = @pagerduty.find_schedule(next_oncall[:schedule][:name])
if next_oncall[:schedule].nil?
schedule = nil
next_oncall = nil
else
schedule = @pagerduty.find_schedule(next_oncall[:schedule][:name])
end
else
schedule = @pagerduty.find_schedule(query[:schedule])
next_oncall = @pagerduty.next_oncall(person.id, schedule.id)
Expand All @@ -126,7 +131,7 @@ def lookup_person(query, event_data)
person: person,
schedule: schedule
}
if next_oncall
unless next_oncall.nil?
output_data[:time] = person.parse_time(next_oncall[:start])
end

Expand Down
1 change: 1 addition & 0 deletions lib/pagerbot/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def self.display_time(time)
end

def self.display_schedule(schedule, text=nil)
return 'any schedule' if schedule.nil?
url = PagerBot.pagerduty.uri_base+"/schedules##{schedule.id}"
link_to(url, text || schedule.name)
end
Expand Down
6 changes: 5 additions & 1 deletion templates/lookup_person_irc.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% if time.nil? %>
<%= person.name %> is not scheduled to go on <%= schedule.name %>
<%= person.name %> is not scheduled to go on <% if schedule.nil? %>
any schedule
<% else %>
<%= schedule.name %>
<% end %>
<% elsif time < Time.now %>
<%= person.name %> is on <%= schedule.name %> now
<% else %>
Expand Down
6 changes: 5 additions & 1 deletion templates/lookup_person_slack.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% if time.nil? %>
<%= person.name %> is not scheduled to go on <%= utilities.display_schedule(schedule) %>.
<%= person.name %> is not scheduled to go on <% if schedule.nil? %>
any schedule
<% else %>
<%= utilities.display_schedule(schedule) %>
<% end %>
<% elsif time < Time.now %>
<%= person.name %> is on <%= utilities.display_schedule(schedule) %> now.
<% else %>
Expand Down
13 changes: 13 additions & 0 deletions test/unit/pagerbot/action_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ def event_data(opts={nick: "karl"})

assert_equal("Karl-Aksel Puulmann is on Primary breakage now", response.fetch(:message))
end

it 'special case: on schedule `call` should succeed if person is not to go on any schedule' do
@pagerduty.expects(:next_oncall)
.with('P123456', nil)
.returns schedule: nil

response = @manager.lookup_person({
:person => "karl",
:schedule => "call"
}, event_data)

assert_equal("Karl-Aksel Puulmann is not scheduled to go on any schedule", response.fetch(:message))
end
end

describe 'who is on schedule X' do
Expand Down

0 comments on commit 736a89c

Please sign in to comment.