class Fastlane::Actions::LatestHockeyBuildNumberAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/latest_hockey_build_number/actions/latest_hockey_build_number_action.rb, line 44
def self.authors
  ["pahnev", "FlixBus (original author)"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/latest_hockey_build_number/actions/latest_hockey_build_number_action.rb, line 48
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "FL_HOCKEY_API_TOKEN",
                                 description: "API Token for Hockey Access",
                                 verify_block: proc do |value|
                                   UI.user_error!("No API token for Hockey given, pass using `api_token: 'token'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :bundle_id,
                                 env_name: "FL_HOCKEY_BUNDLE_ID",
                                 description: "Bundle ID of the application",
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
                                 verify_block: proc do |value|
                                   UI.user_error!("No bundle ID for Hockey given, pass using `bundle_id: 'bundle id'`") unless value and !value.empty?
                                 end),
  ]
end
description() click to toggle source
# File lib/fastlane/plugin/latest_hockey_build_number/actions/latest_hockey_build_number_action.rb, line 40
def self.description
  "Gets latest version number of the app with the bundle id from HockeyApp"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/latest_hockey_build_number/actions/latest_hockey_build_number_action.rb, line 66
def self.is_supported?(platform)
  [:ios, :android].include? platform
end
run(config) click to toggle source
# File lib/fastlane/plugin/latest_hockey_build_number/actions/latest_hockey_build_number_action.rb, line 7
def self.run(config)
  host_uri = URI.parse('https://rink.hockeyapp.net')
  http = Net::HTTP.new(host_uri.host, host_uri.port)
  http.use_ssl = true
  list_request = Net::HTTP::Get.new('/api/2/apps')
  list_request['X-HockeyAppToken'] = config[:api_token]
  list_response = http.request(list_request)
  app_list = JSON.parse(list_response.body)['apps']

  app = app_list.find { |app| app['bundle_identifier'] == config[:bundle_id] }

  if app.nil?
    UI.error "No application with bundle id #{config[:bundle_id]}"
    return nil
  end

  app_identifier = app['public_identifier']

  details_request = Net::HTTP::Get.new("/api/2/apps/#{app_identifier}/app_versions?page=1")
  details_request['X-HockeyAppToken'] = config[:api_token]
  details_response = http.request(details_request)

  app_details = JSON.parse(details_response.body)
  latest_build = app_details['app_versions'].find{ |version| version['status'] != -1 }

  if latest_build.nil?
    UI.error "The app has no versions yet"
    return nil
  end

  return latest_build['version']
end