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)
|
return @environment_url if defined?(@environment_url)
|
||||||
|
|
||||||
@environment_url =
|
@environment_url =
|
||||||
if unexpanded_url = options.dig(:environment, :url)
|
if unexpanded_url = options&.dig(:environment, :url)
|
||||||
ExpandVariables.expand(unexpanded_url, simple_variables)
|
ExpandVariables.expand(unexpanded_url, simple_variables)
|
||||||
else
|
else
|
||||||
persisted_environment&.external_url
|
persisted_environment&.external_url
|
||||||
|
|
|
@ -46,7 +46,7 @@ class CreateDeploymentService
|
||||||
end
|
end
|
||||||
|
|
||||||
def environment_options
|
def environment_options
|
||||||
@environment_options ||= job.options[:environment] || {}
|
@environment_options ||= job.options&.dig(:environment) || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_stop
|
def on_stop
|
||||||
|
|
|
@ -212,12 +212,9 @@ class Gitlab::Seeder::CycleAnalytics
|
||||||
merge_requests.each do |merge_request|
|
merge_requests.each do |merge_request|
|
||||||
Timecop.travel 12.hours.from_now
|
Timecop.travel 12.hours.from_now
|
||||||
|
|
||||||
CreateDeploymentService.new(merge_request.project, @user, {
|
job = merge_request.head_pipeline.builds.where.not(environment: nil).last
|
||||||
environment: 'production',
|
|
||||||
ref: 'master',
|
CreateDeploymentService.new(job).execute
|
||||||
tag: false,
|
|
||||||
sha: @project.repository.commit('master').sha
|
|
||||||
}).execute
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,6 @@ describe CreateDeploymentService, services: true do
|
||||||
let(:service) { described_class.new(job) }
|
let(:service) { described_class.new(job) }
|
||||||
|
|
||||||
describe '#execute' do
|
describe '#execute' do
|
||||||
|
|
||||||
subject { service.execute }
|
subject { service.execute }
|
||||||
|
|
||||||
context 'when no environments exist' do
|
context 'when no environments exist' do
|
||||||
|
|
|
@ -51,12 +51,41 @@ module CycleAnalyticsHelpers
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy_master(environment: 'production')
|
def deploy_master(environment: 'production')
|
||||||
CreateDeploymentService.new(project, user, {
|
dummy_job =
|
||||||
environment: environment,
|
case environment
|
||||||
ref: 'master',
|
when 'production'
|
||||||
tag: false,
|
dummy_production_job
|
||||||
sha: project.repository.commit('master').sha
|
when 'staging'
|
||||||
}).execute
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue