module GemsuranceSlack
Constants
- VERSION
Public Class Methods
check_and_notify()
click to toggle source
# File lib/gemsurance_slack.rb, line 10 def self.check_and_notify abort "Error: environment variables SLACK_WEBHOOK_URL or SLACK_CHANNEL empty." unless initialize_slack_notifier @gems_infos = Gemsurance::Runner.new.run.gem_infos vulnerables_notification outdated_notification end
Private Class Methods
gems_count_string(count)
click to toggle source
# File lib/gemsurance_slack.rb, line 65 def self.gems_count_string(count) count == 1 ? "1 gem is" : "#{count} gems are" end
initialize_slack_notifier()
click to toggle source
# File lib/gemsurance_slack.rb, line 21 def self.initialize_slack_notifier webhook_url = ENV["SLACK_WEBHOOK_URL"] channel = ENV["SLACK_CHANNEL"] return false unless webhook_url && channel @notifier = Slack::Notifier.new webhook_url, :channel => channel end
outdated_notification()
click to toggle source
# File lib/gemsurance_slack.rb, line 47 def self.outdated_notification outdated = @gems_infos.select(&:outdated?) return if outdated.empty? @notifier.ping "", :icon_emoji => ":warning:", :username => "Gemsurance Warning", :attachments => [{ :fallback => "#{project_name}, #{gems_count_string(outdated.count)} out of date.", :pretext => "#{project_name}, #{gems_count_string(outdated.count)} out of date.", :color => "warning", :fields => [{ :title => outdated.map(&:name).join(", ") }] }] end
project_name()
click to toggle source
# File lib/gemsurance_slack.rb, line 61 def self.project_name ENV["SLACK_APP_NAME"] || "" end
vulnerables_notification()
click to toggle source
# File lib/gemsurance_slack.rb, line 29 def self.vulnerables_notification vulnerables = @gems_infos.select(&:vulnerable?) return if vulnerables.empty? @notifier.ping "", :icon_emoji => ":rotating_light:", :username => "Gemsurance Alert", :attachments => [{ :fallback => "#{project_name}, #{gems_count_string(vulnerables.count)} vulnerable.", :pretext => "#{project_name}, #{gems_count_string(vulnerables.count)} vulnerable.", :color => "danger", :fields => vulnerables.map do |gm| { :title => gm.name, :value => "Update v#{gm.current_version} to v#{gm.newest_version} (#{gm.vulnerabilities.map(&:title).join(", ")})", :short => false } end }] end