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(
|
2016-09-13 12:14:55 +00:00
|
|
|
name: expanded_name
|
2016-06-14 16:34:48 +00:00
|
|
|
)
|
2016-06-10 21:36:54 +00:00
|
|
|
|
2016-09-13 12:14:55 +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
|
2016-09-13 12:14:55 +00:00
|
|
|
|
|
|
|
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
|