class Fastlane::Actions::ZealotVersionCheckAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 164
def self.authors
  ['icyleaf']
end
available_options() click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 70
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :endpoint,
                                 env_name: 'ZEALOT_ENDPOINT',
                                 description: 'The endpoint of zealot',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :token,
                                 env_name: 'ZEALOT_TOKEN',
                                 description: 'The token of user',
                                 sensitive: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No user token for Zealot given, pass using `token: 'token'`") if value.nil? || value.empty?
                                 end,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :channel_key,
                                 env_name: 'ZEALOT_CHANNEL_KEY',
                                 description: 'The key of app\'s channel',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :bundle_id,
                                 env_name: 'ZEALOT_BUNDLE_ID',
                                 description: 'The bundle id(package name) of app',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :release_version,
                                 env_name: 'ZEALOT_RELEASE_VERSION',
                                 description: 'The release version of app',
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :build_version,
                                 env_name: 'ZEALOT_BUILD_VERSION',
                                 description: 'The build version of app',
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :git_commit,
                                 env_name: 'ZEALOT_GIT_COMMIT',
                                 description: 'The latest git commit of app',
                                 default_value: ENV['GIT_COMMIT'] || ENV['CI_COMMIT_SHA'],
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :verify_ssl,
                                 env_name: 'ZEALOT_VERIFY_SSL',
                                 description: 'Should verify SSL of zealot service',
                                 optional: true,
                                 default_value: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :hide_user_token,
                                 env_name: 'ZEALOT_HIDE_USER_TOKEN',
                                 description: 'replase user token to *** to keep secret',
                                 optional: true,
                                 default_value: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :fail_on_error,
                                 env_name: 'ZEALOT_FAIL_ON_ERROR',
                                 description: 'Should an error http request cause a failure? (true/false)',
                                 optional: true,
                                 default_value: false,
                                 type: Boolean)
  ]
end
category() click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 160
def self.category
  :beta
end
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 66
def self.description
  'Check app version exists from Zealot'
end
example_code() click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 129
def self.example_code
  [
    'zealot_version_check(
      endpoint: "...",
      token: "...",
      channel_key: "...",
      bundle_id: "im.ews.zealot",
      git_commit: "ec7b5859f77882892325840eae0716fcaab6c14f"
    )',
    'zealot_version_check(
      endpoint: "...",
      token: "...",
      channel_key: "...",
      bundle_id: "im.ews.zealot",
      release_version: "1.0.0",
      build_version: "1"
    )',
  ]
end
is_supported?(_) click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 168
def self.is_supported?(_)
  true
end
output() click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 149
def self.output
  [
    ['ZEALOT_VERSION_EXISTED', 'The result of app verison existed (Boolean)'],
    ['ZEAALOT_ERROR_MESSAGE', 'The error message during upload process']
  ]
end
return_value() click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 156
def self.return_value
  Boolean
end
run(params) click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 23
def self.run(params)
  response = check_app_version(params)
  parse_response(response, params[:fail_on_error])
end

Private Class Methods

parse_response(response, fail_on_error) click to toggle source
# File lib/fastlane/plugin/zealot/actions/zealot_version_check.rb, line 28
def self.parse_response(response, fail_on_error)
  UI.verbose "[status] #{response.status}"
  UI.verbose "[body] #{response.body}"

  is_existed = case response.status
               when 200 then true
               when 404 then false
               end

  return show_error(response.body['error'], fail_on_error) if is_existed.nil?

  Actions.lane_context[SharedValues::ZEALOT_VERSION_EXISTED] = is_existed

  if is_existed
    context = response.body

    Actions.lane_context[SharedValues::ZEALOT_LATEST_RELEASE_ID] = context['id']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_RELEASE_VERSION] = context['release_version']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_BUILD_VERSION] = context['build_version']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_VERSION] = context['version']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_RELEASE_URL] = context['release_url']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_INSTALL_URL] = context['install_url']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_QRCODE_URL] = context['qrcode_url']
    Actions.lane_context[SharedValues::ZEALOT_LATEST_CONTEXT] = context

    UI.important 'Found app version, you can skip upload it'
  else
    UI.success 'Not found app version, you can upload it'
  end

  is_existed
end