fastlane-plugin-wpmreleasetoolkit 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d9be2ee64770a3941008419d8e2ecf628602daf4eec75ea263ba01e9e65c68c
|
4
|
+
data.tar.gz: d086e3da1934ec77a8bf9eb32d1353bf421777d23b862d42be9710f0067dcb59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b610679c97791c79e672d13b45c113a704d148cc19452b06344f3bb8b3f4a8352ba395aa1b8d6c124f193a11fedede7db0e3bb8c80deb56bfee42c8f7e8f659a
|
7
|
+
data.tar.gz: 7df6ece08b5d4f4f408de507b660c09864121147ff2db52406efc04edfd1fa15f368384e8e7d1073b0e3acc61ec694558e4e7e25e40b1f5cfddc367d8ee2b55c
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Fastlane
|
2
|
+
module Actions
|
3
|
+
class CheckTranslationProgressAction < Action
|
4
|
+
def self.run(params)
|
5
|
+
require_relative '../../helper/glotpress_helper'
|
6
|
+
|
7
|
+
UI.message('Checking translations status...')
|
8
|
+
|
9
|
+
under_threshold_langs = check_translations(
|
10
|
+
glotpress_url: params[:glotpress_url],
|
11
|
+
language_codes: params[:language_codes],
|
12
|
+
abort_on_violations: params[:abort_on_violations],
|
13
|
+
threshold: params[:min_acceptable_translation_percentage]
|
14
|
+
)
|
15
|
+
|
16
|
+
unless under_threshold_langs.empty?
|
17
|
+
check_results(
|
18
|
+
under_threshold_langs: under_threshold_langs,
|
19
|
+
threshold: params[:min_acceptable_translation_percentage],
|
20
|
+
skip_confirm: params[:skip_confirm]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
UI.success('Done')
|
25
|
+
end
|
26
|
+
|
27
|
+
# Check the status of the translations and returns the list of violations
|
28
|
+
#
|
29
|
+
# @param [String] URL to the GlotPress project.
|
30
|
+
# @param [String] The list of codes (in GlotPress format) of the languages to check.
|
31
|
+
# @param [Bool] Whether to abort on the first found violation or not.
|
32
|
+
# @param [Integer] The minimum acceptable percentage of translated strings.
|
33
|
+
#
|
34
|
+
# @return [Array] The list of violations (array of hashes of "language code" and "current percentage")
|
35
|
+
#
|
36
|
+
def self.check_translations(glotpress_url:, language_codes:, abort_on_violations:, threshold:)
|
37
|
+
under_threshold_langs = []
|
38
|
+
|
39
|
+
data = begin
|
40
|
+
Fastlane::Helper::GlotPressHelper.get_translation_status_data(glotpress_url: glotpress_url)
|
41
|
+
rescue StandardError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
UI.abort_with_message!("Can't retrieve data from #{glotpress_url}") if data.nil? || data.empty?
|
45
|
+
|
46
|
+
language_codes.each do |language_code|
|
47
|
+
UI.message("> Getting translation status for #{language_code}")
|
48
|
+
progress = begin
|
49
|
+
Fastlane::Helper::GlotPressHelper.get_translation_status(
|
50
|
+
data: data,
|
51
|
+
language_code: language_code
|
52
|
+
)
|
53
|
+
rescue StandardError
|
54
|
+
-1
|
55
|
+
end
|
56
|
+
|
57
|
+
if abort_on_violations
|
58
|
+
UI.abort_with_message!("Can't get data for language #{language_code}") if progress == -1
|
59
|
+
UI.abort_with_message!("#{language_code} is translated #{progress}% which is under the required #{threshold}%.") if progress < threshold
|
60
|
+
end
|
61
|
+
|
62
|
+
UI.message("Language #{language_code} is #{progress}% translated.")
|
63
|
+
under_threshold_langs.push({ lang: language_code, progress: progress }) if progress < threshold
|
64
|
+
end
|
65
|
+
|
66
|
+
under_threshold_langs
|
67
|
+
end
|
68
|
+
|
69
|
+
# Report the status of the translations and verify whether to abort or not
|
70
|
+
#
|
71
|
+
# @param [Array] The list of violations (array of hashes of "language code" and "current percentage")
|
72
|
+
# @param [Integer] The minimum acceptable percentage of translated strings.
|
73
|
+
# @param [Bool] If true, continue after the report without asking the user.
|
74
|
+
#
|
75
|
+
def self.check_results(under_threshold_langs:, threshold:, skip_confirm:)
|
76
|
+
message = "The translations for the following languages are below the #{threshold}% threshold:\n"
|
77
|
+
|
78
|
+
under_threshold_langs.each do |lang|
|
79
|
+
message << " - #{lang[:lang]} is at #{lang[:progress]}%.\n"
|
80
|
+
end
|
81
|
+
|
82
|
+
if skip_confirm
|
83
|
+
UI.important(message)
|
84
|
+
elsif UI.interactive?
|
85
|
+
UI.abort_with_message!('Aborted by user!') unless UI.confirm("#{message}Do you want to continue?")
|
86
|
+
else
|
87
|
+
UI.abort_with_message!(message)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#####################################################
|
92
|
+
# @!group Documentation
|
93
|
+
#####################################################
|
94
|
+
|
95
|
+
def self.description
|
96
|
+
'Raises an error if the translation percentage is lower than the provided threshold'
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.details
|
100
|
+
'This actions checks the current status of the translations on GlotPress ' \
|
101
|
+
'and raises an error if it\'s below the provided threshold'
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.available_options
|
105
|
+
[
|
106
|
+
FastlaneCore::ConfigItem.new(key: :glotpress_url,
|
107
|
+
env_name: 'FL_CHECK_TRANSLATION_PROGRESS_GLOTPRESS_URL',
|
108
|
+
description: 'URL to the GlotPress project',
|
109
|
+
type: String),
|
110
|
+
FastlaneCore::ConfigItem.new(key: :language_codes,
|
111
|
+
env_name: 'FL_CHECK_TRANSLATION_PROGRESS_LANGUAGE_CODES',
|
112
|
+
description: 'The list of the codes of the languages to check',
|
113
|
+
type: Array,
|
114
|
+
optional: true,
|
115
|
+
# Default to Mag16.
|
116
|
+
default_value: 'ar de es fr he id it ja ko nl pt-br ru sv tr zh-cn zh-tw'.split()),
|
117
|
+
FastlaneCore::ConfigItem.new(key: :min_acceptable_translation_percentage,
|
118
|
+
env_name: 'FL_CHECK_TRANSLATION_PROGRESS_MIN_ACCEPTABLE_TRANSLATION_PERCENTAGE',
|
119
|
+
description: 'The threshold under which an error is raised',
|
120
|
+
type: Integer,
|
121
|
+
optional: true,
|
122
|
+
default_value: 100),
|
123
|
+
FastlaneCore::ConfigItem.new(key: :abort_on_violations,
|
124
|
+
env_name: 'FL_CHECK_TRANSLATION_ABORT_ON_VIOLATIONS',
|
125
|
+
description: 'Should we abort with a global error if any violations are found?',
|
126
|
+
optional: true,
|
127
|
+
default_value: true,
|
128
|
+
is_string: false),
|
129
|
+
FastlaneCore::ConfigItem.new(key: :skip_confirm,
|
130
|
+
env_name: 'FL_CHECK_TRANSLATION_SKIP_CONFIRM',
|
131
|
+
description: 'Move ahead without requesting confirmation if violations are found. Only works if "abort_on_violations" is disabled',
|
132
|
+
optional: true,
|
133
|
+
default_value: false,
|
134
|
+
is_string: false),
|
135
|
+
]
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.authors
|
139
|
+
['loremattei']
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.is_supported?(platform)
|
143
|
+
true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Helper
|
6
|
+
class GlotPressHelper
|
7
|
+
# Gets the data about status of the translation.
|
8
|
+
#
|
9
|
+
# @param [String] URL to the GlotPress project.
|
10
|
+
#
|
11
|
+
# @return [Array] Data from GlotPress project overview page.
|
12
|
+
#
|
13
|
+
def self.get_translation_status_data(glotpress_url:)
|
14
|
+
uri = URI.parse(glotpress_url)
|
15
|
+
response = Net::HTTP.get_response(uri)
|
16
|
+
response = Net::HTTP.get_response(URI.parse(response.header['location'])) if response.code == '301'
|
17
|
+
|
18
|
+
response.body.split("\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
# Gets the status of the translation for a given language.
|
22
|
+
#
|
23
|
+
# @param [Array] Data from GlotPress project overview page.
|
24
|
+
# @param [String] The code of the language to get information about (GlotPress format).
|
25
|
+
#
|
26
|
+
# @return [Integer] The percentage of the translated strings.
|
27
|
+
#
|
28
|
+
def self.get_translation_status(data:, language_code:)
|
29
|
+
current = extract_value_from_translation_info_data(data: data, language_code: language_code, status: 'current')
|
30
|
+
fuzzy = extract_value_from_translation_info_data(data: data, language_code: language_code, status: 'fuzzy')
|
31
|
+
untranslated = extract_value_from_translation_info_data(data: data, language_code: language_code, status: 'untranslated')
|
32
|
+
waiting = extract_value_from_translation_info_data(data: data, language_code: language_code, status: 'waiting')
|
33
|
+
|
34
|
+
(current * 100 / (current + fuzzy + untranslated + waiting)).round
|
35
|
+
end
|
36
|
+
|
37
|
+
# Extract the number of strings which are in the given status.
|
38
|
+
#
|
39
|
+
# @param [Array] Data from GlotPress project overview page.
|
40
|
+
# @param [String] The code of the language to get information about (GlotPress format).
|
41
|
+
# @param [String] The status which data should be extracted for.
|
42
|
+
#
|
43
|
+
# @return [Integer] The percentage of the translated strings.
|
44
|
+
#
|
45
|
+
def self.extract_value_from_translation_info_data(data:, language_code:, status:)
|
46
|
+
regex = "\/#{language_code}\/.*#{status}.*>([0-9,]+)"
|
47
|
+
|
48
|
+
# 1. Grep the line with contains the required info.
|
49
|
+
# 2. Match the info and extract the value in group 1.
|
50
|
+
# 3. Values use comma as thousands separator, so remove it.
|
51
|
+
# 4. Convert to integer.
|
52
|
+
data.grep(/#{regex}/)[0].match(/#{regex}/)[1].gsub(/,/, '').to_i
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-wpmreleasetoolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorenzo Mattei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
@@ -385,6 +385,7 @@ files:
|
|
385
385
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_metadata.rb
|
386
386
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_release_notes.rb
|
387
387
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_for_toolkit_updates_action.rb
|
388
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/check_translation_progress.rb
|
388
389
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/circleci_trigger_job_action.rb
|
389
390
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb
|
390
391
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_new_milestone_action.rb
|
@@ -440,6 +441,7 @@ files:
|
|
440
441
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/filesystem_helper.rb
|
441
442
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb
|
442
443
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb
|
444
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_helper.rb
|
443
445
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_adc_app_sizes_helper.rb
|
444
446
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb
|
445
447
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_helper.rb
|