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)
|
|
|
|
environment = create_or_find_environment(params[:environment])
|
2016-06-10 21:36:54 +00:00
|
|
|
|
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,
|
|
|
|
deployable: deployable,
|
|
|
|
)
|
2016-06-10 21:36:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-14 11:51:12 +00:00
|
|
|
def create_or_find_environment(environment)
|
|
|
|
find_environment(environment) || create_environment(environment)
|
2016-06-10 21:36:54 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 11:51:12 +00:00
|
|
|
def create_environment(environment)
|
|
|
|
project.environments.create(name: environment)
|
2016-06-10 21:36:54 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 11:51:12 +00:00
|
|
|
def find_environment(environment)
|
|
|
|
project.environments.find_by(name: environment)
|
2016-06-10 21:36:54 +00:00
|
|
|
end
|
|
|
|
end
|