Fix other use of CreateDeploymentService and make
it a bit more robust against missing options, which we did guard on for some cases.
This commit is contained in:
parent
e9a98d3d2d
commit
f62603286d
|
@ -148,7 +148,7 @@ module Ci
|
|||
return @environment_url if defined?(@environment_url)
|
||||
|
||||
@environment_url =
|
||||
if unexpanded_url = options.dig(:environment, :url)
|
||||
if unexpanded_url = options&.dig(:environment, :url)
|
||||
ExpandVariables.expand(unexpanded_url, simple_variables)
|
||||
else
|
||||
persisted_environment&.external_url
|
||||
|
|
|
@ -46,7 +46,7 @@ class CreateDeploymentService
|
|||
end
|
||||
|
||||
def environment_options
|
||||
@environment_options ||= job.options[:environment] || {}
|
||||
@environment_options ||= job.options&.dig(:environment) || {}
|
||||
end
|
||||
|
||||
def on_stop
|
||||
|
|
|
@ -212,12 +212,9 @@ class Gitlab::Seeder::CycleAnalytics
|
|||
merge_requests.each do |merge_request|
|
||||
Timecop.travel 12.hours.from_now
|
||||
|
||||
CreateDeploymentService.new(merge_request.project, @user, {
|
||||
environment: 'production',
|
||||
ref: 'master',
|
||||
tag: false,
|
||||
sha: @project.repository.commit('master').sha
|
||||
}).execute
|
||||
job = merge_request.head_pipeline.builds.where.not(environment: nil).last
|
||||
|
||||
CreateDeploymentService.new(job).execute
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,6 @@ describe CreateDeploymentService, services: true do
|
|||
let(:service) { described_class.new(job) }
|
||||
|
||||
describe '#execute' do
|
||||
|
||||
subject { service.execute }
|
||||
|
||||
context 'when no environments exist' do
|
||||
|
|
|
@ -51,12 +51,41 @@ module CycleAnalyticsHelpers
|
|||
end
|
||||
|
||||
def deploy_master(environment: 'production')
|
||||
CreateDeploymentService.new(project, user, {
|
||||
environment: environment,
|
||||
ref: 'master',
|
||||
tag: false,
|
||||
sha: project.repository.commit('master').sha
|
||||
}).execute
|
||||
dummy_job =
|
||||
case environment
|
||||
when 'production'
|
||||
dummy_production_job
|
||||
when 'staging'
|
||||
dummy_staging_job
|
||||
else
|
||||
raise ArgumentError
|
||||
end
|
||||
|
||||
CreateDeploymentService.new(dummy_job).execute
|
||||
end
|
||||
|
||||
def dummy_production_job
|
||||
@dummy_job ||= new_dummy_job('production')
|
||||
end
|
||||
|
||||
def dummy_staging_job
|
||||
@dummy_job ||= new_dummy_job('staging')
|
||||
end
|
||||
|
||||
def dummy_pipeline
|
||||
@dummy_pipeline ||=
|
||||
Ci::Pipeline.new(sha: project.repository.commit('master').sha)
|
||||
end
|
||||
|
||||
def new_dummy_job(environment)
|
||||
Ci::Build.new(
|
||||
project: project,
|
||||
user: user,
|
||||
environment: environment,
|
||||
ref: 'master',
|
||||
tag: false,
|
||||
name: 'dummy',
|
||||
pipeline: dummy_pipeline)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue