Created
September 14, 2016 12:09
-
-
Save kevsmith/fa190bc5f4fe41f7974a1fcb4a7eb6d5 to your computer and use it in GitHub Desktop.
How does this work?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# For reference see https://github.com/cogcmd/pagerduty/blob/master/lib/cog_cmd/pagerduty/oncall.rb#L29 | |
# Some test users | |
users = [{id: 1, | |
name: "Bob", | |
email: "[email protected]", | |
policy_ids: [1,2]}, | |
{id: 2, | |
name: "Sue", | |
email: "[email protected]", | |
policy_ids: [1]}, | |
{id: 3, | |
name: "Fred", | |
email: "[email protected]", | |
policy_ids: [2]}, | |
{id: 4, | |
name: "Heather", | |
email: "[email protected]", | |
policy_ids: [3]}] | |
# Some test services | |
services = [{id: 100, | |
name: "Corp Site", | |
escalation_policy: {id: 1}}, | |
{id: 101, | |
name: "Prod DB", | |
escalation_policy: {id: 2}}, | |
{id: 102, | |
name: "Network", | |
escalation_policy: {id: 3}}] | |
formatted_services = services.map do |service| | |
oncall_via_find = users.find do |user| | |
user[:policy_ids].include?(service[:escalation_policy][:id]) | |
end | |
oncall_via_select = users.select do |user| | |
user[:policy_ids].include?(service[:escalation_policy][:id]) | |
end | |
{ | |
name: service[:name], | |
id: service[:id], | |
oncall_find: oncall_via_find, | |
oncall_select: oncall_via_select | |
} | |
end | |
# Note the difference between oncall_find and oncall_select | |
formatted_services.each do | s | | |
puts "---------------" | |
puts "Name: #{s[:name]}" | |
puts "Id: #{s[:id]}" | |
puts "++++++++++" | |
puts "Oncall users (find): #{s[:oncall_find]}" | |
puts "++++++++++" | |
puts "Oncall users (select): #{s[:oncall_select]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment