class Semvergen::SlackNotifier

Public Class Methods

new(opts) click to toggle source
# File lib/semvergen/slack_notifier.rb, line 7
def initialize(opts)
  @webhook_url = opts["webhook_url"]
  @username    = opts["username"]
  @icons       = opts["icons"]
end

Public Instance Methods

attachment(gem_name, new_version, change_log_message) click to toggle source
# File lib/semvergen/slack_notifier.rb, line 34
def attachment(gem_name, new_version, change_log_message)
  {
    title:     "#{user} has published a new version of '#{gem_name}'",
    fallback:  change_log_message,
    fields:    [
                 {title: "Version", value: new_version},
                 {title: "Change Log", value: change_log_message}

               ],
    color:     "good",
    mrkdwn_in: ["text", "title", "fallback", "fields"]
  }
end
gem_published(gem_name, new_version, change_log_message) click to toggle source
# File lib/semvergen/slack_notifier.rb, line 13
def gem_published(gem_name, new_version, change_log_message)
  options = {}
  options[:icon_url] = @icons.sample if @icons
  options[:attachments] = [attachment(gem_name, new_version, change_log_message)]
  notifier.ping "Semvergen: release #{gem_name}", options
end
notifier() click to toggle source
# File lib/semvergen/slack_notifier.rb, line 20
def notifier
  @notifier ||= Slack::Notifier.new(
    @webhook_url,
    username: @username
  )
end
user() click to toggle source
# File lib/semvergen/slack_notifier.rb, line 27
def user
  [
    ENV["USER"],
    `whoami`
  ].compact.detect { |u| !u.nil? }
end