Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-11-17 02:23:05 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-11-17 02:23:05 +0300
commitd6e00f5373e24deaa7f143f5445ae9461ef5f615 (patch)
tree59d784dd10d349d54fda8924d00a79946bf1bfdb /app
parent2b8292cd49dbc68b02f46f865b7115191bf2de07 (diff)
Improve specs and add missing cases that were not supported
Diffstat (limited to 'app')
-rw-r--r--app/helpers/environment_helper.rb20
-rw-r--r--app/models/ci/build.rb20
-rw-r--r--app/views/projects/builds/show.html.haml27
-rw-r--r--app/workers/build_success_worker.rb2
4 files changed, 48 insertions, 21 deletions
diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb
index 1e2a8c7ddbd..ea34bce9367 100644
--- a/app/helpers/environment_helper.rb
+++ b/app/helpers/environment_helper.rb
@@ -2,20 +2,28 @@ module EnvironmentHelper
def environment_for_build(project, build)
return unless build.environment
- environment_name = ExpandVariables.expand(build.environment, build.variables)
- project.environments.find_by(name: environment_name)
+ project.environments.find_by(name: build.expanded_environment_name)
end
def environment_link_for_build(project, build)
environment = environment_for_build(project, build)
- return unless environment
-
- link_to environment.name, namespace_project_environment_path(project.namespace, project, environment)
+ if environment
+ link_to environment.name, namespace_project_environment_path(project.namespace, project, environment)
+ else
+ content_tag :span, build.expanded_environment_name
+ end
end
- def deployment_link(project, deployment)
+ def deployment_link(deployment)
return unless deployment
link_to "##{deployment.id}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable]
end
+
+ def last_deployment_link_for_environment_build(project, build)
+ environment = environment_for_build(project, build)
+ return unless environment
+
+ deployment_link(environment.last_deployment)
+ end
end
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 09bbea1c653..e0e7a8caeea 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -127,8 +127,24 @@ module Ci
!self.pipeline.statuses.latest.include?(self)
end
- def deployable?
- self.environment.present?
+ def expanded_environment_name
+ ExpandVariables.expand(environment, variables) if environment
+ end
+
+ def starts_environment?
+ self.environment.present? && self.environment_action == 'start'
+ end
+
+ def stops_environment?
+ self.environment.present? && self.environment_action == 'stop'
+ end
+
+ def environment_action
+ self.options.fetch(:environment, {}).fetch(:action, 'start')
+ end
+
+ def outdated_deployment?
+ success? && !last_deployment.try(:last?)
end
def last_deployment
diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml
index 488688a7d59..d799671058d 100644
--- a/app/views/projects/builds/show.html.haml
+++ b/app/views/projects/builds/show.html.haml
@@ -26,26 +26,29 @@
= link_to namespace_project_runners_path(@build.project.namespace, @build.project) do
Runners page
- - if @build.deployable?
+ - if @build.environment.present? && @build.starts_environment?
.prepend-top-default
.environment-information
- - if @build.status == 'success' && (!@build.last_deployment.try(:last?))
+ - if @build.outdated_deployment?
= ci_icon_for_status('success_with_warnings')
- else
= ci_icon_for_status(@build.status)
- - last_deployment = @build.last_deployment
- - if @build.complete?
- - if @build.success?
- - if last_deployment.try(:last?)
- This build is the most recent deployment to #{environment_link_for_build(@build.project, @build)}.
- - else
- This build is an out-of-date deployment to #{environment_link_for_build(@build.project, @build)}. View the most recent deployment #{deployment_link(@project, last_deployment)}.
+ - environment = environment_for_build(@build.project, @build)
+ - if @build.success? && @build.last_deployment.present?
+ - if @build.last_deployment.last?
+ This build is the most recent deployment to #{environment_link_for_build(@build.project, @build)}.
- else
- The deployment of this build to #{environment_link_for_build(@build.project, @build)} did not complete.
+ This build is an out-of-date deployment to #{environment_link_for_build(@build.project, @build)}.
+ - if environment.last_deployment
+ View the most recent deployment #{deployment_link(environment.last_deployment)}.
+ - elsif @build.complete? && !@build.success?
+ The deployment of this build to #{environment_link_for_build(@build.project, @build)} did not complete.
- else
- This build is creating a deployment to #{environment_link_for_build(@build.project, @build)} and will overwrite the |
- = link_to "latest deployment.", deployment_link(@project, last_deployment) |
+ This build is creating a deployment to #{environment_link_for_build(@build.project, @build)}
+ - if environment.last_deployment
+ and will overwrite the
+ = link_to 'latest deployment', deployment_link(environment.last_deployment)
.prepend-top-default
- if @build.erased?
diff --git a/app/workers/build_success_worker.rb b/app/workers/build_success_worker.rb
index 1bc9745ecbc..450ba871c4c 100644
--- a/app/workers/build_success_worker.rb
+++ b/app/workers/build_success_worker.rb
@@ -4,7 +4,7 @@ class BuildSuccessWorker
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
- create_deployment(build) if build.deployable?
+ create_deployment(build) if build.environment.present?
end
end