gitlab-org--gitlab-foss/app/services/create_deployment_service.rb

51 lines
845 B
Ruby
Raw Normal View History

2016-06-10 21:36:54 +00:00
require_relative 'base_service'
class CreateDeploymentService < BaseService
2016-06-14 11:51:12 +00:00
def execute(deployable = nil)
2016-06-14 16:34:48 +00:00
environment = project.environments.find_or_create_by(
name: expanded_name
2016-06-14 16:34:48 +00:00
)
2016-06-10 21:36:54 +00:00
if expanded_url
environment.external_url = expanded_url
end
2016-06-14 11:51:12 +00:00
project.deployments.create(
environment: environment,
ref: params[:ref],
tag: params[:tag],
sha: params[:sha],
user: current_user,
2016-06-14 16:34:48 +00:00
deployable: deployable
2016-06-14 11:51:12 +00:00
)
2016-06-10 21:36:54 +00:00
end
private
def expanded_name
name.expand_variables(variables)
end
def expanded_url
return unless url
@expanded_url ||= url.expand_variables(variables)
end
def name
params[:environment]
end
def url
options[:url]
end
def options
params[:environment] || {}
end
def variables
params[:variables] || []
end
2016-06-10 21:36:54 +00:00
end