Class: Fastlane::Helper::DependencyManagerOutdatedHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/dependency_manager_outdated/helper/dependency_manager_outdated_helper.rb

Class Method Summary collapse

Class Method Details

.generate_slack_attachments(libs) ⇒ Object

def self.generate_slack_attachments(libs)

attachements = []
libs.each do |lib|
  attachement = {title: lib[:name]}
  if lib[:repository]
    attachement[:title_link] = lib[:repository]
  end

  fields = []

  current = lib[:current]
  available = lib[:available]

  if current == available
    attachement[:color] = "warning"
  else
    available = "*#{available}*"
    attachement[:color] = "danger"
  end
  # field[:value] = "#{current} -> #{available} (#{lib[:latest]})"
  # attachement[:fields] = [field]

  fields << {title: "current", value: current, short: true}
  fields << {title: "available", value: "#{available} (Latest: #{lib[:latest]})", short: true}
  attachement[:fields] = fields
  attachements << attachement
end
attachements

end



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fastlane/plugin/dependency_manager_outdated/helper/dependency_manager_outdated_helper.rb', line 87

def self.generate_slack_attachments(libs)
  attachements = []
  libs.each do |lib|
    attachement = {title: lib[:name]}
    if lib[:repository]
      attachement[:title_link] = lib[:repository]
    end

    current = lib[:current]
    available = lib[:available]

    if current == available
      attachement[:color] = "warning"
    else
      available = "*#{available}*"
      attachement[:color] = "danger"
    end
    attachement[:text] = "#{current} -> #{available} (Latest: #{lib[:latest]})"
    attachements << attachement
  end
  attachements
end

.messageObject



15
16
17
# File 'lib/fastlane/plugin/dependency_manager_outdated/helper/dependency_manager_outdated_helper.rb', line 15

def self.message
  ""
end

.nameObject

class methods that you define here become available in your action as ‘Helper::DependencyManagerOutdatedHelper.your_method`



11
12
13
# File 'lib/fastlane/plugin/dependency_manager_outdated/helper/dependency_manager_outdated_helper.rb', line 11

def self.name
  ""
end

.notify_slack(libs) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/dependency_manager_outdated/helper/dependency_manager_outdated_helper.rb', line 19

def self.notify_slack(libs)
  require 'slack-notifier'

  options = DependencyManager.config

  return if options[:skip_slack]
  return if options[:slack_url].to_s.empty?

  ######################
  # see https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/slack.rb
  ######################

  if options[:slack_channel].to_s.length > 0
    channel = options[:slack_channel]
    channel = ('#' + options[:slack_channel]) unless ['#', '@'].include?(channel[0]) # send message to channel by default
  end

  attachements = generate_slack_attachments(libs)

  notifier = Slack::Notifier.new(options[:slack_url], channel: channel, username: options[:slack_username])
  text = "[#{name}] #{message}"

  begin
    results = notifier.ping(text, icon_url: options[:slack_icon_url], attachments: attachements)
  rescue => exception
    UI.error("Exception: #{exception}")
  ensure
    result = results.first if results
    if !result.nil? && result.code.to_i == 200
      UI.success('Successfully sent Slack notification')
    else
      UI.verbose(result) unless result.nil?
      message = "Error pushing Slack message, maybe the integration has no permission to post on this channel? Try removing the channel parameter in your Fastfile, this is usually caused by a misspelled or changed group/channel name or an expired SLACK_URL"
      UI.error(message)
    end
  end
end