fastlane/lib/fastlane/actions/install_xcode_plugin.rb in fastlane-2.50.0.beta.20170731010002 vs fastlane/lib/fastlane/actions/install_xcode_plugin.rb in fastlane-2.50.0
- old
+ new
@@ -2,15 +2,28 @@
module Actions
class InstallXcodePluginAction < Action
def self.run(params)
require 'fileutils'
- unless params[:github].nil?
- github_api_url = params[:github].sub('https://github.com', 'https://api.github.com/repos')
- release = self.fetch_json(github_api_url + '/releases/latest')
- return if release.nil?
- params[:url] = release['assets'][0]['browser_download_url']
+ if params[:github]
+ base_api_url = params[:github].sub('https://github.com', 'https://api.github.com/repos')
+
+ GithubApiAction.run(
+ url: File.join(base_api_url, 'releases/latest'),
+ http_method: 'GET',
+ error_handlers: {
+ 404 => proc do |result|
+ UI.error("No latest release found for the specified GitHub repository")
+ end,
+ '*' => proc do |result|
+ UI.error("GitHub responded with #{response[:status]}:#{response[:body]}")
+ end
+ }
+ ) do |result|
+ return nil if result[:json].nil?
+ params[:url] = result[:json]['assets'][0]['browser_download_url']
+ end
end
zip_path = File.join(Dir.tmpdir, 'plugin.zip')
sh "curl -Lso #{zip_path} #{params[:url]}"
plugins_path = "#{ENV['HOME']}/Library/Application Support/Developer/Shared/Xcode/Plug-ins"
@@ -19,28 +32,10 @@
UI.success("Plugin #{File.basename(params[:url], '.zip')} installed successfully")
UI.message("Please restart Xcode to use the newly installed plugin")
end
- def self.fetch_json(url)
- require 'excon'
- require 'json'
-
- response = Excon.get(url)
-
- if response[:status] != 200
- if response[:status] == 404
- UI.error("No latest release found for the specified GitHub repository")
- else
- UI.error("GitHub responded with #{response[:status]}:#{response[:body]}")
- end
- return nil
- end
-
- JSON.parse(response.body)
- end
-
#####################################################
# @!group Documentation
#####################################################
def self.description
@@ -72,10 +67,10 @@
def self.return_value
end
def self.authors
- ["NeoNachoSoto"]
+ ["NeoNachoSoto", "tommeier"]
end
def self.is_supported?(platform)
[:ios, :mac, :tvos, :watchos, :caros].include?(platform)
end