Class: Popper::Action::Slack

Inherits:
Base
  • Object
show all
Defined in:
lib/popper/action/slack.rb

Class Method Summary collapse

Methods inherited from Base

action_name, do_action?, next_action, next_run, run

Class Method Details

.check_paramsObject



31
32
33
34
# File 'lib/popper/action/slack.rb', line 31

def self.check_params
  @action_config.respond_to?(:channel) &&
  @action_config.respond_to?(:webhook_url)
end

.task(mail, params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/popper/action/slack.rb', line 4

def self.task(mail, params={})
  notifier = ::Slack::Notifier.new(
    @action_config.webhook_url,
    channel: @action_config.channel,
    username: @action_config.user || 'popper',
    link_names: 1
  )

  note = {
    pretext: mail.date.to_s,
    title: mail.subject,
    color: "good"
  }
  note[:text] = mail.utf_body if @action_config.use_body

  body = @action_config.message || "popper mail notification"
  body += " #{@action_config.mentions.join(" ")}" if @action_config.mentions
  %w(
    git
    ghe
  ).each do |name|
    body += " #{name}:#{params[(name + '_url').to_sym]}" if params[(name + '_url').to_sym]
  end

  notifier.ping body, attachments: [note]
end