Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions lib/ghb/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/ghb/aws_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lib/ghb/build_context.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions lib/ghb/code_deploy_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions lib/ghb/gitignore_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/ghb/language_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/ghb/licenses_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions lib/ghb/linter_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/ghb/slack_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/ghb/variables_job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/ghb/aws_job_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))

Expand All @@ -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))

Expand Down Expand Up @@ -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))

Expand Down
64 changes: 40 additions & 24 deletions spec/ghb/code_deploy_job_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand Down Expand Up @@ -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
)

Expand All @@ -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
)

Expand Down Expand Up @@ -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
)

Expand Down
Loading
Loading