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:
Lin Jen-Shin 2017-06-02 02:46:34 +08:00
parent e9a98d3d2d
commit f62603286d
5 changed files with 40 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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