Class: Fastlane::Actions::GpDownloadmetadataAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



88
89
90
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 88

def self.authors
  ['Automattic']
end

.available_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 48

def self.available_options
  # Define all options your action supports.

  # Below a few examples
  [
    FastlaneCore::ConfigItem.new(key: :project_url,
                                 env_name: 'FL_DOWNLOAD_METADATA_PROJECT_URL', # The name of the environment variable
                                 description: 'GlotPress project URL'),
    FastlaneCore::ConfigItem.new(key: :target_files,
                                 env_name: 'FL_DOWNLOAD_METADATA_TARGET_FILES',
                                 description: 'The hash with the path to the target files and the key to use to extract their content',
                                 type: Hash),
    FastlaneCore::ConfigItem.new(key: :locales,
                                 env_name: 'FL_DOWNLOAD_METADATA_LOCALES',
                                 description: 'The hash with the GlotPress locale and the project locale association',
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :source_locale,
                                 env_name: 'FL_DOWNLOAD_METADATA_SOURCE_LOCALE',
                                 description: 'The source locale code',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :download_path,
                                 env_name: 'FL_DOWNLOAD_METADATA_DOWNLOAD_PATH',
                                 description: 'The path of the target files',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :auto_retry,
                                 env_name: 'FL_DOWNLOAD_METADATA_AUTO_RETRY',
                                 description: 'Whether to auto retry downloads after Too Many Requests error',
                                 type: FastlaneCore::Boolean,
                                 optional: true,
                                 default_value: true),
  ]
end

.descriptionObject



40
41
42
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 40

def self.description
  'Download translated metadata'
end

.detailsObject



44
45
46
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 44

def self.details
  'Downloads tranlated metadata from GlotPress and updates local files'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 92

def self.is_supported?(platform)
  true
end

.outputObject



81
82
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 81

def self.output
end

.return_valueObject



84
85
86
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 84

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb', line 7

def self.run(params)
  # fastlane will take care of reading in the parameter and fetching the environment variable:
  UI.message "Project URL: #{params[:project_url]}"
  UI.message "Locales: #{params[:locales].inspect}"
  UI.message "Source locale: #{params[:source_locale].nil? ? '-' : params[:source_locale]}"
  UI.message "Path: #{params[:download_path]}"
  UI.message "Auto-retry: #{params[:auto_retry]}"

  # Check download path
  FileUtils.mkdir_p(params[:download_path])

  # Download
  downloader = Fastlane::Helper::MetadataDownloader.new(params[:download_path], params[:target_files], params[:auto_retry])

  params[:locales].each do |loc|
    if loc.is_a?(Array)
      UI.message "Downloading language: #{loc[1]}"
      complete_url = "#{params[:project_url]}#{loc[0]}/default/export-translations/?filters[status]=current&format=json"
      downloader.download(loc[1], complete_url, loc[1] == params[:source_locale])
    end

    next unless loc.is_a?(String)

    UI.message "Downloading language: #{loc}"
    complete_url = "#{params[:project_url]}#{loc}/default/export-translations/?filters[status]=current&format=json"
    downloader.download(loc, complete_url, loc == params[:source_locale])
  end
end