Class: Fastlane::PluginUpdateManager

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/plugins/plugin_update_manager.rb

Overview

Alert the user when updates for plugins are available

Class Method Summary collapse

Class Method Details

.fetch_latest_version(gem_name) ⇒ Object



60
61
62
63
64
# File 'fastlane/lib/fastlane/plugins/plugin_update_manager.rb', line 60

def self.fetch_latest_version(gem_name)
  Gem::Version.new(PluginManager.fetch_gem_info_from_rubygems(gem_name)["version"])
rescue
  nil
end

.plugin_referencesObject



56
57
58
# File 'fastlane/lib/fastlane/plugins/plugin_update_manager.rb', line 56

def self.plugin_references
  Fastlane.plugin_manager.plugin_references
end

.server_resultsObject



66
67
68
# File 'fastlane/lib/fastlane/plugins/plugin_update_manager.rb', line 66

def self.server_results
  @server_results ||= {}
end

.show_update_statusObject



17
18
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
# File 'fastlane/lib/fastlane/plugins/plugin_update_manager.rb', line 17

def self.show_update_status
  return if FastlaneCore::Env.truthy?("FASTLANE_SKIP_UPDATE_CHECK")

  # We set self.server_results to be nil
  # this way the table is not printed twice
  # (next to the summary table or when an exception happens)
  return unless self.server_results.count > 0

  rows = []
  self.plugin_references.each do |plugin_name, current_plugin|
    latest_version = self.server_results[plugin_name]
    next if latest_version.nil?
    current_version = Gem::Version.new(current_plugin[:version_number])
    next if current_version >= latest_version

    rows << [
      plugin_name.gsub(PluginManager.plugin_prefix, ''),
      current_version.to_s.red,
      latest_version.to_s.green
    ]
  end

  if rows.empty?
    UI.verbose("All plugins are up to date")
    return
  end

  require 'terminal-table'
  puts(Terminal::Table.new({
    rows: FastlaneCore::PrintTable.transform_output(rows),
    title: "Plugin updates available".yellow,
    headings: ["Plugin", "Your Version", "Latest Version"]
  }))
  UI.message("To update all plugins, just run")
  UI.command "bundle exec fastlane update_plugins"
  puts('')
  @server_results = nil
end

.start_looking_for_updatesObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'fastlane/lib/fastlane/plugins/plugin_update_manager.rb', line 4

def self.start_looking_for_updates
  return if FastlaneCore::Env.truthy?("FASTLANE_SKIP_UPDATE_CHECK")

  Thread.new do
    self.plugin_references.each do |plugin_name, current_plugin|
      begin
        self.server_results[plugin_name] = fetch_latest_version(plugin_name)
      rescue
      end
    end
  end
end