Module: Build::Notifications
- Defined in:
- lib/travis/model/build/notifications.rb
Constant Summary collapse
- DEFAULTS =
{ :success => { :email => :change, :webhook => :always, :irc => :always }, :failure => { :email => :always, :webhook => :always, :irc => :always } }
Instance Method Summary collapse
- #email_recipients ⇒ Object
- #irc_channels ⇒ Object
- #notify_on_failure?(type) ⇒ Boolean
- #notify_on_success?(type) ⇒ Boolean
- #send_email_notifications? ⇒ Boolean
- #send_irc_notifications? ⇒ Boolean
- #send_notifications_for?(type) ⇒ Boolean
- #send_webhook_notifications? ⇒ Boolean
- #webhooks ⇒ Object
Instance Method Details
#email_recipients ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/travis/model/build/notifications.rb', line 40 def email_recipients @email_recipients ||= if (recipients = notification_values(:email, :recipients)).any? recipients else notifications[:recipients] || default_email_recipients # TODO deprecate recipients end end |
#irc_channels ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/travis/model/build/notifications.rb', line 52 def irc_channels @irc_channels ||= notification_values(:irc, :channels).inject(Hash.new([])) do |servers, url| server_and_port, channel = url.split('#') server, port = server_and_port.split(':') servers[[server, port]] += [channel] servers end end |
#notify_on_failure?(type) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/travis/model/build/notifications.rb', line 33 def notify_on_failure?(type) !!if failed? config = config_with_fallbacks(type, :on_failure, DEFAULTS[:failure][type]) config == :always || (config == :change && previous_passed?) end end |
#notify_on_success?(type) ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/travis/model/build/notifications.rb', line 26 def notify_on_success?(type) !!if passed? config = config_with_fallbacks(type, :on_success, DEFAULTS[:success][type]) config == :always || (config == :change && !previous_passed?) end end |
#send_email_notifications? ⇒ Boolean
10 11 12 |
# File 'lib/travis/model/build/notifications.rb', line 10 def send_email_notifications? emails_enabled? && email_recipients.present? && send_notifications_for?(:email) end |
#send_irc_notifications? ⇒ Boolean
18 19 20 |
# File 'lib/travis/model/build/notifications.rb', line 18 def send_irc_notifications? irc_channels.any? && send_notifications_for?(:irc) end |
#send_notifications_for?(type) ⇒ Boolean
22 23 24 |
# File 'lib/travis/model/build/notifications.rb', line 22 def send_notifications_for?(type) previous_on_branch.blank? || notify_on_success?(type) || notify_on_failure?(type) end |
#send_webhook_notifications? ⇒ Boolean
14 15 16 |
# File 'lib/travis/model/build/notifications.rb', line 14 def send_webhook_notifications? webhooks.any? && send_notifications_for?(:webhooks) end |
#webhooks ⇒ Object
48 49 50 |
# File 'lib/travis/model/build/notifications.rb', line 48 def webhooks @webhooks ||= notification_values(:webhooks, :urls).map {|webhook| webhook.split(' ') }.flatten.map(&:strip).reject(&:blank?) end |