summaryrefslogtreecommitdiff
path: root/app/services/create_deployment_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/create_deployment_service.rb')
-rw-r--r--app/services/create_deployment_service.rb38
1 files changed, 35 insertions, 3 deletions
diff --git a/app/services/create_deployment_service.rb b/app/services/create_deployment_service.rb
index c126b2fad31..aad5cc8a15b 100644
--- a/app/services/create_deployment_service.rb
+++ b/app/services/create_deployment_service.rb
@@ -2,9 +2,7 @@ require_relative 'base_service'
class CreateDeploymentService < BaseService
def execute(deployable = nil)
- environment = project.environments.find_or_create_by(
- name: params[:environment]
- )
+ environment = find_or_create_environment
deployment = project.deployments.create(
environment: environment,
@@ -45,4 +43,38 @@ class CreateDeploymentService < BaseService
where.not(id: current_deployment.id).
first
end
+
+ private
+
+ def find_or_create_environment
+ project.environments.find_or_create_by(name: expanded_name) do |environment|
+ environment.external_url = expanded_url
+ end
+ end
+
+ def expanded_name
+ ExpandVariables.expand(name, variables)
+ end
+
+ def expanded_url
+ return unless url
+
+ @expanded_url ||= ExpandVariables.expand(url, variables)
+ end
+
+ def name
+ params[:environment]
+ end
+
+ def url
+ options[:url]
+ end
+
+ def options
+ params[:options] || {}
+ end
+
+ def variables
+ params[:variables] || []
+ end
end