Skip to content

Commit dddcf9e

Browse files
committed
Refactor to make rubocop happy
1 parent 7b44115 commit dddcf9e

2 files changed

Lines changed: 66 additions & 52 deletions

File tree

lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
require "semantic"
66
require_relative "github_actions_helper"
77
require_relative "git_helper"
8+
require_relative "embedded_files_helper"
89

910
module Fastlane
1011
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
1112

1213
module Helper
13-
# This class exceeds the maximum allowed length, so we should refactor it to reduce complexity.
14-
# The rubocop exception has been added in a PR which only added one line to the class, so the
15-
# work to refactor could be hardly justified, but we should prioritise refactoring in a dedicated
16-
# PR or as soon as we touch this file with bigger changes.
17-
# rubocop:disable Metrics/ClassLength
1814
class DdgAppleAutomationHelper
1915
DEFAULT_BRANCH = 'main'
2016
RELEASE_BRANCH = 'release'
@@ -27,21 +23,6 @@ class DdgAppleAutomationHelper
2723
VERSION_CONFIG_DEFINITION = 'MARKETING_VERSION'
2824
BUILD_NUMBER_CONFIG_DEFINITION = 'CURRENT_PROJECT_VERSION'
2925

30-
UPGRADABLE_EMBEDDED_FILES = {
31-
"ios" => Set.new([
32-
'Core/AppPrivacyConfigurationDataProvider.swift',
33-
'Core/AppTrackerDataSetProvider.swift',
34-
'Core/ios-config.json',
35-
'Core/trackerData.json'
36-
]),
37-
"macos" => Set.new([
38-
'DuckDuckGo/ContentBlocker/AppPrivacyConfigurationDataProvider.swift',
39-
'DuckDuckGo/ContentBlocker/AppTrackerDataSetProvider.swift',
40-
'DuckDuckGo/ContentBlocker/trackerData.json',
41-
'DuckDuckGo/ContentBlocker/macos-config.json'
42-
])
43-
}.freeze
44-
4526
def self.release_branch_name(platform, version)
4627
"#{RELEASE_BRANCH}/#{platform}/#{version}"
4728
end
@@ -232,37 +213,7 @@ def self.create_release_branch(platform, version)
232213
end
233214

234215
def self.update_embedded_files(platform, other_action)
235-
pre_update_embedded_tests
236-
Actions.sh("./scripts/update_embedded.sh")
237-
238-
# Verify no unexpected files were modified
239-
git_status = Actions.sh('git', 'status')
240-
modified_files = git_status.split("\n").select { |line| line.include?('modified:') }
241-
modified_files = modified_files.map { |str| str.split(':')[1].strip.delete_prefix('../') }
242-
243-
modified_files.each do |modified_file|
244-
UI.abort_with_message!("Unexpected change to #{modified_file}.") unless UPGRADABLE_EMBEDDED_FILES[platform].any? do |s|
245-
s.include?(modified_file)
246-
end
247-
end
248-
249-
# Run tests (CI will run them separately)
250-
# run_tests(scheme: 'DuckDuckGo Privacy Browser') unless Helper.is_ci?
251-
252-
# Everything looks good: commit and push
253-
unless modified_files.empty?
254-
modified_files.each { |modified_file| Actions.sh('git', 'add', modified_file.to_s) }
255-
Actions.sh('git', 'commit', '-m', 'Update embedded files')
256-
other_action.ensure_git_status_clean
257-
end
258-
end
259-
260-
def pre_update_embedded_tests
261-
tds_perf_test_result = other_action.tds_perf_test
262-
263-
unless tds_perf_test_result
264-
UI.important("TDS performance tests failed. Proceeding with caution.")
265-
end
216+
Helper::EmbeddedFilesHelper.update_embedded_files(platform, other_action)
266217
end
267218

268219
def self.increment_build_number(platform, options, other_action)
@@ -436,7 +387,6 @@ def self.load_file(file)
436387
end
437388
end
438389
end
439-
# rubocop:enable Metrics/ClassLength
440390
end
441391

442392
module FastlaneCore
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require "fastlane_core/configuration/config_item"
2+
require "fastlane_core/ui/ui"
3+
require "httparty"
4+
require "rexml/document"
5+
require "semantic"
6+
require_relative "github_actions_helper"
7+
require_relative "git_helper"
8+
9+
module Fastlane
10+
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
11+
12+
module Helper
13+
class EmbeddedFilesHelper
14+
UPGRADABLE_EMBEDDED_FILES = {
15+
"ios" => Set.new([
16+
'Core/AppPrivacyConfigurationDataProvider.swift',
17+
'Core/AppTrackerDataSetProvider.swift',
18+
'Core/ios-config.json',
19+
'Core/trackerData.json'
20+
]),
21+
"macos" => Set.new([
22+
'DuckDuckGo/ContentBlocker/AppPrivacyConfigurationDataProvider.swift',
23+
'DuckDuckGo/ContentBlocker/AppTrackerDataSetProvider.swift',
24+
'DuckDuckGo/ContentBlocker/trackerData.json',
25+
'DuckDuckGo/ContentBlocker/macos-config.json'
26+
])
27+
}.freeze
28+
29+
def self.update_embedded_files(platform, other_action)
30+
other_action.tds_perf_test
31+
Actions.sh("./scripts/update_embedded.sh")
32+
33+
# Verify no unexpected files were modified
34+
git_status = Actions.sh('git', 'status')
35+
modified_files = git_status.split("\n").select { |line| line.include?('modified:') }
36+
modified_files = modified_files.map { |str| str.split(':')[1].strip.delete_prefix('../') }
37+
38+
modified_files.each do |modified_file|
39+
UI.abort_with_message!("Unexpected change to #{modified_file}.") unless UPGRADABLE_EMBEDDED_FILES[platform].any? do |s|
40+
s.include?(modified_file)
41+
end
42+
end
43+
44+
# Run tests (CI will run them separately)
45+
# run_tests(scheme: 'DuckDuckGo Privacy Browser') unless Helper.is_ci?
46+
47+
# Everything looks good: commit and push
48+
unless modified_files.empty?
49+
modified_files.each { |modified_file| Actions.sh('git', 'add', modified_file.to_s) }
50+
Actions.sh('git', 'commit', '-m', 'Update embedded files')
51+
other_action.ensure_git_status_clean
52+
end
53+
end
54+
55+
def pre_update_embedded_tests
56+
tds_perf_test_result = other_action.tds_perf_test
57+
58+
unless tds_perf_test_result
59+
UI.important("TDS performance tests failed. Proceeding with caution.")
60+
end
61+
end
62+
end
63+
end
64+
end

0 commit comments

Comments
 (0)