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, action?, next_action, next_run, run

Class Method Details

.check_paramsObject



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

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
# 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,
    text: mail.subject,
    color: "good"
  }

  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