Class: Kuroko2::Workflow::Notifier::Webhook

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_builderObject (readonly)

Returns the value of attribute message_builder.



5
6
7
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 5

def message_builder
  @message_builder
end

Instance Method Details

#notify_back_to_normalObject



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: message_builder.back_to_normal_text,
    )
  )
end

#notify_cancellationObject



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: message_builder.failure_text,
        message: @instance.logs.reverse.detect{ |log| log.level == 'WARN' }.try!(:message),
      )
    )
  end
end

#notify_criticalObject



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: message_builder.failure_text,
      message: @instance.logs.last(2).first.message,
    )
  )
end

#notify_failureObject



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: message_builder.failure_text,
      message: @instance.logs.last(2).first.message,
    )
  )
end

#notify_finishedObject



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: message_builder.finished_text,
      )
    )
  end
end

#notify_launchObject



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: message_builder.launched_text,
        message: @instance.logs.reverse.detect{ |log| log.level == 'INFO' }.try!(:message),
      )
    )
  end
end

#notify_long_elapsed_timeObject



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: message_builder.long_elapsed_time_text,
    )
  )
end

#notify_retryingObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/autoload/kuroko2/workflow/notifier/webhook.rb', line 30

def notify_retrying
  if @definition.hipchat_notify_finished?
    request(
      build_payload(
        action: 'notify_retrying',
        level: 'INFO',
        subject: message_builder.retrying_text,
        message: @instance.logs.last(2).first.message,
      )
    )
  end
end

#notify_skippingObject



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: message_builder.skipping_text,
        message: @instance.logs.last(2).first.message,
      )
    )
  end
end