class Taperole::Notifiers::Slack
Public Class Methods
new(webhook_url, deploy_info)
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 6 def initialize(webhook_url, deploy_info) @notifier = ::Slack::Notifier.new webhook_url @notifier.username = 'Tape' @deploy_info = deploy_info end
Public Instance Methods
update(status)
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 12 def update(status) @status = status @notifier.ping( "", # TODO: Fill in real icon url icon_url: 'https://image.freepik.com/free-icon/adhesive-tape_318-42276.png', attachments: attachments ) end
Private Instance Methods
attachments()
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 24 def attachments a = {} a[:text] = message a[:color] = color a[:fields] = fields unless @status == :start [a] end
color()
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 52 def color case @status when :start then "#a9a9a9" when :success then "good" when :fail then "danger" end end
fields()
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 32 def fields [ { title: "Project", value: project_link, short: true }, { title: "Hosts/Env", value: @deploy_info[:hosts], short: true }, { title: "Author", value: @deploy_info[:user], short: true } ] end
gh_link_base()
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 60 def gh_link_base @deploy_info[:repo].sub(/^git@github.com:/, 'http://github.com/').sub(/.git$/, '') end
message()
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 68 def message case @status when :start user = @deploy_info[:user] app = @deploy_info[:app_name] hosts = @deploy_info[:hosts] "#{user} started deploying #{app} to #{hosts}" when :success "The deploy was successful!" when :fail "The deploy failed!" end end
project_link()
click to toggle source
# File lib/taperole/notifiers/slack.rb, line 64 def project_link "<#{gh_link_base}|#{@deploy_info[:app_name]}>" end