Class: Kuroko2::Workflow::Notifier::Webhook
- Inherits:
-
Object
- Object
- Kuroko2::Workflow::Notifier::Webhook
- Defined in:
- lib/autoload/kuroko2/workflow/notifier/webhook.rb
Constant Summary collapse
- HASH_ALGORITHM =
'sha256'
- HMAC_DIGEST =
OpenSSL::Digest.new(HASH_ALGORITHM)
Instance Attribute Summary collapse
-
#message_builder ⇒ Object
readonly
Returns the value of attribute message_builder.
Instance Method Summary collapse
-
#initialize(instance) ⇒ Webhook
constructor
A new instance of Webhook.
- #notify_back_to_normal ⇒ Object
- #notify_cancellation ⇒ Object
- #notify_critical ⇒ Object
- #notify_failure ⇒ Object
- #notify_finished ⇒ Object
- #notify_launch ⇒ Object
- #notify_long_elapsed_time ⇒ Object
- #notify_retrying ⇒ Object
- #notify_skipping ⇒ Object
Constructor Details
#initialize(instance) ⇒ Webhook
Returns a new instance of Webhook.
10 11 12 13 14 15 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 10 def initialize(instance) @instance = instance @definition = instance.job_definition @message_builder = Workflow::Notifier::Concerns::ChatMessageBuilder.new(instance) @secret_token = Kuroko2.config.notifiers.webhook.try!(:secret_token) end |
Instance Attribute Details
#message_builder ⇒ Object (readonly)
Returns the value of attribute message_builder.
5 6 7 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 5 def @message_builder end |
Instance Method Details
#notify_back_to_normal ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 103 def notify_back_to_normal request( build_payload( action: 'notify_back_to_normal', level: 'SUCCESS', subject: .back_to_normal_text, ) ) end |
#notify_cancellation ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 56 def notify_cancellation if @definition.notify_cancellation || @definition.hipchat_notify_finished? request( build_payload( action: 'notify_cancellation', level: 'WARNING', subject: .failure_text, message: @instance.logs.reverse.detect{ |log| log.level == 'WARN' }.try!(:message), ) ) end end |
#notify_critical ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 80 def notify_critical request( build_payload( action: 'notify_critical', level: 'CRITICAL', subject: .failure_text, message: @instance.logs.last(2).first., ) ) end |
#notify_failure ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 69 def notify_failure request( build_payload( action: 'notify_failure', level: 'FAILURE', subject: .failure_text, message: @instance.logs.last(2).first., ) ) end |
#notify_finished ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 91 def notify_finished if @definition.hipchat_notify_finished? request( build_payload( action: 'notify_finished', level: 'SUCCESS', subject: .finished_text, ) ) end end |
#notify_launch ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 17 def notify_launch if @definition.hipchat_notify_finished? request( build_payload( action: 'notify_launch', level: 'INFO', subject: .launched_text, message: @instance.logs.reverse.detect{ |log| log.level == 'INFO' }.try!(:message), ) ) end end |
#notify_long_elapsed_time ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 113 def notify_long_elapsed_time request( build_payload( action: 'notify_long_elapsed_time', level: 'WARNING', subject: .long_elapsed_time_text, ) ) end |
#notify_retrying ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 30 def if @definition.hipchat_notify_finished? request( build_payload( action: 'notify_retrying', level: 'INFO', subject: ., message: @instance.logs.last(2).first., ) ) end end |
#notify_skipping ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 43 def notify_skipping if @definition.hipchat_notify_finished? request( build_payload( action: 'notify_skipping', level: 'INFO', subject: .skipping_text, message: @instance.logs.last(2).first., ) ) end end |