diff --git a/lib/ghb/application.rb b/lib/ghb/application.rb index 7b640f9..9898bd7 100644 --- a/lib/ghb/application.rb +++ b/lib/ghb/application.rb @@ -9,6 +9,7 @@ require_relative 'auto_merge_manager' require_relative 'aws_job_builder' +require_relative 'build_context' require_relative 'code_deploy_job_builder' require_relative 'dependabot_manager' require_relative 'dockerhub_manager' @@ -65,27 +66,25 @@ def execute workflow_read workflow_set_defaults - VariablesJobBuilder.new(options: @options, new_workflow: @new_workflow).build - - LinterJobBuilder.new( + context = BuildContext.new( options: @options, - submodules: @submodules, old_workflow: @old_workflow, new_workflow: @new_workflow, - file_cache: @file_cache - ).build + file_cache: @file_cache, + submodules: @submodules + ) - licenses_builder = LicensesJobBuilder.new(options: @options, old_workflow: @old_workflow, new_workflow: @new_workflow) + VariablesJobBuilder.new(context: context).build + + LinterJobBuilder.new(context: context).build + + licenses_builder = LicensesJobBuilder.new(context: context) licenses_builder.build @unit_tests_conditions = licenses_builder.unit_tests_conditions language_builder = LanguageJobBuilder.new( - options: @options, - submodules: @submodules, - old_workflow: @old_workflow, - new_workflow: @new_workflow, + context: context, unit_tests_conditions: @unit_tests_conditions, - file_cache: @file_cache, dependencies_commands: @dependencies_commands ) language_builder.build @@ -95,15 +94,10 @@ def execute collect_required_status_checks - CodeDeployJobBuilder.new( - options: @options, - old_workflow: @old_workflow, - new_workflow: @new_workflow, - code_deploy_pre_steps: @code_deploy_pre_steps - ).build + CodeDeployJobBuilder.new(context: context, code_deploy_pre_steps: @code_deploy_pre_steps).build - AwsJobBuilder.new(options: @options, old_workflow: @old_workflow, new_workflow: @new_workflow).build - SlackJobBuilder.new(options: @options, old_workflow: @old_workflow, new_workflow: @new_workflow).build + AwsJobBuilder.new(context: context).build + SlackJobBuilder.new(context: context).build workflow_write @@ -116,7 +110,7 @@ def execute AutoMergeManager.new(auto_merge_workflow: @auto_merge_workflow).save DockerhubManager.new(dockerhub_workflow: @dockerhub_workflow).save - GitignoreManager.new(options: @options, submodules: @submodules, file_cache: @file_cache).update + GitignoreManager.new(context: context).update RepositoryConfigurator.new(options: @options, required_status_checks: @required_status_checks, default_branch: @default_branch).configure @exit_code diff --git a/lib/ghb/aws_job_builder.rb b/lib/ghb/aws_job_builder.rb index eddfd1c..10657fa 100644 --- a/lib/ghb/aws_job_builder.rb +++ b/lib/ghb/aws_job_builder.rb @@ -3,10 +3,10 @@ module GHB # Builds the "AWS Commands" job in the workflow. class AwsJobBuilder - def initialize(options:, old_workflow:, new_workflow:) - @options = options - @old_workflow = old_workflow - @new_workflow = new_workflow + def initialize(context:) + @options = context.options + @old_workflow = context.old_workflow + @new_workflow = context.new_workflow end def build diff --git a/lib/ghb/build_context.rb b/lib/ghb/build_context.rb new file mode 100644 index 0000000..a5f3333 --- /dev/null +++ b/lib/ghb/build_context.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module GHB + # Immutable bundle of the values shared across job builders, replacing the + # recurring (options:, old_workflow:, new_workflow:, file_cache:, submodules:) + # keyword-argument clump. Builders that need extra inputs take those as + # additional keyword arguments alongside `context:`. + # + # The referenced workflow / cache / submodules objects are still mutated in + # place by the pipeline; only the container itself is frozen. + class BuildContext + attr_reader :options, :old_workflow, :new_workflow, :file_cache, :submodules + + def initialize(options:, new_workflow: nil, old_workflow: nil, file_cache: {}, submodules: []) + @options = options + @old_workflow = old_workflow + @new_workflow = new_workflow + @file_cache = file_cache + @submodules = submodules + freeze + end + end +end diff --git a/lib/ghb/code_deploy_job_builder.rb b/lib/ghb/code_deploy_job_builder.rb index 714e6d7..7db0ee0 100644 --- a/lib/ghb/code_deploy_job_builder.rb +++ b/lib/ghb/code_deploy_job_builder.rb @@ -3,10 +3,10 @@ module GHB # Builds the "Code Deploy" jobs in the workflow. class CodeDeployJobBuilder - def initialize(options:, old_workflow:, new_workflow:, code_deploy_pre_steps:) - @options = options - @old_workflow = old_workflow - @new_workflow = new_workflow + def initialize(context:, code_deploy_pre_steps:) + @options = context.options + @old_workflow = context.old_workflow + @new_workflow = context.new_workflow @code_deploy_pre_steps = code_deploy_pre_steps end diff --git a/lib/ghb/gitignore_manager.rb b/lib/ghb/gitignore_manager.rb index 89b0af0..4820bf7 100644 --- a/lib/ghb/gitignore_manager.rb +++ b/lib/ghb/gitignore_manager.rb @@ -9,10 +9,10 @@ module GHB class GitignoreManager include FileScanner - def initialize(options:, submodules:, file_cache:) - @options = options - @submodules = submodules - @file_cache = file_cache + def initialize(context:) + @options = context.options + @submodules = context.submodules + @file_cache = context.file_cache end def update diff --git a/lib/ghb/language_job_builder.rb b/lib/ghb/language_job_builder.rb index eb957f1..6d93b86 100644 --- a/lib/ghb/language_job_builder.rb +++ b/lib/ghb/language_job_builder.rb @@ -15,13 +15,13 @@ class LanguageJobBuilder attr_reader :code_deploy_pre_steps, :dependencies_steps, :dependencies_commands - def initialize(options:, submodules:, old_workflow:, new_workflow:, unit_tests_conditions:, file_cache:, dependencies_commands:) - @options = options - @submodules = submodules - @old_workflow = old_workflow - @new_workflow = new_workflow + def initialize(context:, unit_tests_conditions:, dependencies_commands:) + @options = context.options + @submodules = context.submodules + @old_workflow = context.old_workflow + @new_workflow = context.new_workflow @unit_tests_conditions = unit_tests_conditions - @file_cache = file_cache + @file_cache = context.file_cache @code_deploy_pre_steps = [] @dependencies_steps = [] @dependencies_commands = dependencies_commands diff --git a/lib/ghb/licenses_job_builder.rb b/lib/ghb/licenses_job_builder.rb index 325436b..65056e2 100644 --- a/lib/ghb/licenses_job_builder.rb +++ b/lib/ghb/licenses_job_builder.rb @@ -5,10 +5,10 @@ module GHB class LicensesJobBuilder attr_reader :unit_tests_conditions - def initialize(options:, old_workflow:, new_workflow:) - @options = options - @old_workflow = old_workflow - @new_workflow = new_workflow + def initialize(context:) + @options = context.options + @old_workflow = context.old_workflow + @new_workflow = context.new_workflow @unit_tests_conditions = nil end diff --git a/lib/ghb/linter_job_builder.rb b/lib/ghb/linter_job_builder.rb index 5ecd69e..6d7cf67 100644 --- a/lib/ghb/linter_job_builder.rb +++ b/lib/ghb/linter_job_builder.rb @@ -7,12 +7,12 @@ module GHB class LinterJobBuilder include FileScanner - def initialize(options:, submodules:, old_workflow:, new_workflow:, file_cache:) - @options = options - @submodules = submodules - @old_workflow = old_workflow - @new_workflow = new_workflow - @file_cache = file_cache + def initialize(context:) + @options = context.options + @submodules = context.submodules + @old_workflow = context.old_workflow + @new_workflow = context.new_workflow + @file_cache = context.file_cache end def build diff --git a/lib/ghb/slack_job_builder.rb b/lib/ghb/slack_job_builder.rb index 3260ccc..f80e4a7 100644 --- a/lib/ghb/slack_job_builder.rb +++ b/lib/ghb/slack_job_builder.rb @@ -3,10 +3,10 @@ module GHB # Builds the "Publish Statuses" (Slack) job in the workflow. class SlackJobBuilder - def initialize(options:, old_workflow:, new_workflow:) - @options = options - @old_workflow = old_workflow - @new_workflow = new_workflow + def initialize(context:) + @options = context.options + @old_workflow = context.old_workflow + @new_workflow = context.new_workflow end def build diff --git a/lib/ghb/variables_job_builder.rb b/lib/ghb/variables_job_builder.rb index c7a386d..f62c741 100644 --- a/lib/ghb/variables_job_builder.rb +++ b/lib/ghb/variables_job_builder.rb @@ -3,9 +3,9 @@ module GHB # Builds the "Prepare Variables" job in the workflow. class VariablesJobBuilder - def initialize(options:, new_workflow:) - @options = options - @new_workflow = new_workflow + def initialize(context:) + @options = context.options + @new_workflow = context.new_workflow end def build diff --git a/spec/ghb/aws_job_builder_spec.rb b/spec/ghb/aws_job_builder_spec.rb index a3a47a9..3f9019b 100644 --- a/spec/ghb/aws_job_builder_spec.rb +++ b/spec/ghb/aws_job_builder_spec.rb @@ -16,7 +16,7 @@ it 'returns early when only_dependabot is true' do options = instance_double(GHB::Options, only_dependabot: true) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) builder.build @@ -26,7 +26,7 @@ it 'returns early when .aws file missing' do # rubocop:disable RSpec/ExampleLength options = instance_double(GHB::Options, only_dependabot: false) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('.aws').and_return(false)) @@ -44,7 +44,7 @@ do_name('Prepare Variables') end - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('.aws').and_return(true)) @@ -85,7 +85,7 @@ do_name('Prepare Variables') end - builder = described_class.new(options: options, old_workflow: old_wf, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_wf, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('.aws').and_return(true)) diff --git a/spec/ghb/code_deploy_job_builder_spec.rb b/spec/ghb/code_deploy_job_builder_spec.rb index 956c21d..a2cf2e6 100644 --- a/spec/ghb/code_deploy_job_builder_spec.rb +++ b/spec/ghb/code_deploy_job_builder_spec.rb @@ -17,9 +17,11 @@ it 'returns early without adding jobs' do # rubocop:disable RSpec/ExampleLength builder = described_class.new( - options: options, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_workflow, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) @@ -38,9 +40,11 @@ allow(File).to(receive(:exist?).with('appspec.yml').and_return(false)) builder = described_class.new( - options: options, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_workflow, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) @@ -66,9 +70,11 @@ it 'adds codedeploy and environment jobs' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations builder = described_class.new( - options: options, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_workflow, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) @@ -82,9 +88,11 @@ it 'creates the codedeploy job with correct name and needs' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations builder = described_class.new( - options: options, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_workflow, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) @@ -97,9 +105,11 @@ it 'creates beta_deploy, rc_deploy, and prod_deploy environment jobs' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations builder = described_class.new( - options: options, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_workflow, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) @@ -142,9 +152,11 @@ end builder = described_class.new( - options: options, - old_workflow: old_wf, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_wf, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) @@ -164,9 +176,11 @@ pre_steps = [pre_step] builder = described_class.new( - options: options, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_workflow, + new_workflow: new_workflow + ), code_deploy_pre_steps: pre_steps ) @@ -199,9 +213,11 @@ end builder = described_class.new( - options: options, - old_workflow: old_wf, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: options, + old_workflow: old_wf, + new_workflow: new_workflow + ), code_deploy_pre_steps: code_deploy_pre_steps ) diff --git a/spec/ghb/gitignore_manager_spec.rb b/spec/ghb/gitignore_manager_spec.rb index 6c43e8f..5c3f99a 100644 --- a/spec/ghb/gitignore_manager_spec.rb +++ b/spec/ghb/gitignore_manager_spec.rb @@ -12,7 +12,7 @@ excluded_folders: [] ) end - let(:manager) { described_class.new(options: mock_options, submodules: submodules, file_cache: file_cache) } + let(:manager) { described_class.new(context: GHB::BuildContext.new(options: mock_options, submodules: submodules, file_cache: file_cache)) } let(:minimal_gitignore_config) do { @@ -32,7 +32,7 @@ describe '#update' do it 'returns early when skip_gitignore is true' do skip_options = instance_double(GHB::Options, skip_gitignore: true) - skip_manager = described_class.new(options: skip_options, submodules: [], file_cache: {}) + skip_manager = described_class.new(context: GHB::BuildContext.new(options: skip_options, submodules: [], file_cache: {})) allow(File).to(receive(:exist?).with('.gitignore')) @@ -204,7 +204,7 @@ languages_config_file: 'config/languages.yaml', excluded_folders: %w[var tmp] ) - mgr = described_class.new(options: options, submodules: ['pnp-scripts'], file_cache: {}) + mgr = described_class.new(context: GHB::BuildContext.new(options: options, submodules: ['pnp-scripts'], file_cache: {})) allow(mgr).to(receive(:excluded_dirs_from_config).and_return(['.git'])) expect(mgr.__send__(:build_gitignore_excluded_paths)).to(eq(%w[.git pnp-scripts var tmp])) diff --git a/spec/ghb/language_job_builder_spec.rb b/spec/ghb/language_job_builder_spec.rb index bd59fd4..68528d8 100644 --- a/spec/ghb/language_job_builder_spec.rb +++ b/spec/ghb/language_job_builder_spec.rb @@ -28,12 +28,14 @@ let(:builder) do described_class.new( - options: mock_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: mock_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ), unit_tests_conditions: unit_tests_conditions, - file_cache: file_cache, dependencies_commands: dependencies_commands ) end @@ -88,12 +90,14 @@ it 'returns early when only_dependabot is true' do # rubocop:disable RSpec/ExampleLength dependabot_options = instance_double(GHB::Options, only_dependabot: true) dependabot_builder = described_class.new( - options: dependabot_options, - submodules: [], - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: dependabot_options, + submodules: [], + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -329,12 +333,14 @@ ) non_strict_builder = described_class.new( - options: non_strict_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: non_strict_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -370,12 +376,14 @@ ) codedeploy_builder = described_class.new( - options: codedeploy_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: codedeploy_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -414,12 +422,14 @@ env_mismatch_workflow.env[:'MONGODB-VERSION'] = '7.0' env_mismatch_builder = described_class.new( - options: non_strict_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: env_mismatch_workflow, + context: GHB::BuildContext.new( + options: non_strict_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: env_mismatch_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -459,12 +469,14 @@ version_mismatch_workflow.env[:'MONGODB-VERSION'] = '7.0' version_mismatch_builder = described_class.new( - options: mock_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: version_mismatch_workflow, + context: GHB::BuildContext.new( + options: mock_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: version_mismatch_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -500,12 +512,14 @@ ) license_builder = described_class.new( - options: license_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: license_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -545,12 +559,14 @@ ) mono_builder = described_class.new( - options: mono_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: mono_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) @@ -588,12 +604,14 @@ ) mono_svc_builder = described_class.new( - options: mono_options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, + context: GHB::BuildContext.new( + options: mono_options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ), unit_tests_conditions: unit_tests_conditions, - file_cache: {}, dependencies_commands: +'' ) diff --git a/spec/ghb/licenses_job_builder_spec.rb b/spec/ghb/licenses_job_builder_spec.rb index 356035a..b2e098b 100644 --- a/spec/ghb/licenses_job_builder_spec.rb +++ b/spec/ghb/licenses_job_builder_spec.rb @@ -16,7 +16,7 @@ it 'returns early when only_dependabot is true' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations options = instance_double(GHB::Options, only_dependabot: true) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) builder.build @@ -27,7 +27,7 @@ it 'sets unit_tests_conditions with Podfile.lock present' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations options = instance_double(GHB::Options, only_dependabot: false) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('Podfile.lock').and_return(true)) @@ -40,7 +40,7 @@ it 'sets unit_tests_conditions without Podfile.lock' do # rubocop:disable RSpec/ExampleLength options = instance_double(GHB::Options, only_dependabot: false, skip_license_check: false) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('Podfile.lock').and_return(false)) @@ -52,7 +52,7 @@ it 'adds licenses job when skip_license_check is false and no Podfile.lock' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations options = instance_double(GHB::Options, only_dependabot: false, skip_license_check: false) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('Podfile.lock').and_return(false)) @@ -68,7 +68,7 @@ it 'skips licenses job when skip_license_check is true' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations options = instance_double(GHB::Options, only_dependabot: false, skip_license_check: true) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('Podfile.lock').and_return(false)) @@ -98,7 +98,7 @@ options = instance_double(GHB::Options, only_dependabot: false, skip_license_check: false) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_wf, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_wf, new_workflow: new_workflow)) allow(File).to(receive(:exist?).with('Podfile.lock').and_return(false)) diff --git a/spec/ghb/linter_job_builder_spec.rb b/spec/ghb/linter_job_builder_spec.rb index e550582..a26697d 100644 --- a/spec/ghb/linter_job_builder_spec.rb +++ b/spec/ghb/linter_job_builder_spec.rb @@ -25,11 +25,13 @@ it 'returns early without adding jobs' do # rubocop:disable RSpec/ExampleLength builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) builder.build @@ -57,11 +59,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Mock find_files_matching: return matches for rubocop pattern, empty for others @@ -105,11 +109,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Return matches for everything to prove ignored linters are skipped @@ -140,11 +146,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Return matches for everything to prove semgrep is skipped @@ -187,11 +195,13 @@ local_submodules = [] builder = described_class.new( - options: options, - submodules: local_submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: local_submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) allow(builder).to(receive(:find_files_matching).and_return([])) @@ -220,11 +230,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Only match eslint pattern (js files) @@ -268,11 +280,13 @@ allow(File).to(receive(:delete)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Only match semgrep pattern @@ -331,11 +345,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: {} + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: {} + ) ) # Override cached_file_read to return our custom config @@ -379,11 +395,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Only match rubocop pattern (Fastfile) @@ -437,11 +455,13 @@ allow(File).to(receive(:delete)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # No files match any linter @@ -475,11 +495,13 @@ allow(File).to(receive(:delete)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Return matches for non-ignored linters so they proceed normally @@ -513,11 +535,13 @@ allow(File).to(receive(:delete)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # No files match any linter pattern @@ -559,11 +583,13 @@ allow(File).to(receive(:delete)) builder = described_class.new( - options: options, - submodules: [], - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: [], + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Only match semgrep pattern @@ -616,11 +642,13 @@ local_submodules = [] builder = described_class.new( - options: options, - submodules: local_submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: local_submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Only match golangci pattern (go files) @@ -662,11 +690,13 @@ allow(File).to(receive(:exist?).with('.gitmodules').and_return(false)) builder = described_class.new( - options: options, - submodules: submodules, - old_workflow: old_workflow, - new_workflow: new_workflow, - file_cache: file_cache + context: GHB::BuildContext.new( + options: options, + submodules: submodules, + old_workflow: old_workflow, + new_workflow: new_workflow, + file_cache: file_cache + ) ) # Only match eslint pattern (js files) diff --git a/spec/ghb/slack_job_builder_spec.rb b/spec/ghb/slack_job_builder_spec.rb index 10149cb..7ade7fd 100644 --- a/spec/ghb/slack_job_builder_spec.rb +++ b/spec/ghb/slack_job_builder_spec.rb @@ -16,7 +16,7 @@ it 'returns early when only_dependabot is true' do options = instance_double(GHB::Options, only_dependabot: true, skip_slack: false) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) builder.build @@ -26,7 +26,7 @@ it 'returns early when skip_slack is true' do options = instance_double(GHB::Options, only_dependabot: false, skip_slack: true) new_workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) builder.build @@ -42,7 +42,7 @@ do_name('Prepare Variables') end - builder = described_class.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_workflow, new_workflow: new_workflow)) builder.build @@ -77,7 +77,7 @@ do_name('Prepare Variables') end - builder = described_class.new(options: options, old_workflow: old_wf, new_workflow: new_workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, old_workflow: old_wf, new_workflow: new_workflow)) builder.build diff --git a/spec/ghb/variables_job_builder_spec.rb b/spec/ghb/variables_job_builder_spec.rb index a7575fd..c44aebd 100644 --- a/spec/ghb/variables_job_builder_spec.rb +++ b/spec/ghb/variables_job_builder_spec.rb @@ -5,7 +5,7 @@ it 'returns early when only_dependabot is true' do options = instance_double(GHB::Options, only_dependabot: true) workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, new_workflow: workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, new_workflow: workflow)) builder.build @@ -15,7 +15,7 @@ it 'adds variables job to workflow' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations options = instance_double(GHB::Options, only_dependabot: false) workflow = GHB::Workflow.new('Test') - builder = described_class.new(options: options, new_workflow: workflow) + builder = described_class.new(context: GHB::BuildContext.new(options: options, new_workflow: workflow)) builder.build