summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-16 10:54:20 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-16 10:54:20 +0100
commite49229aa04144e0ce7672ad0a34a24da9b09027e (patch)
treed2f5e0878537deba7ef48d60871311b12797272e
parentc95b88e649789e6dc27e4b97856a8bdf069312cc (diff)
downloadgitlab-ce-e49229aa04144e0ce7672ad0a34a24da9b09027e.tar.gz
Refactor methods for environments in project model
-rw-r--r--app/models/environment.rb2
-rw-r--r--app/models/project.rb17
-rw-r--r--app/services/ci/stop_environments_service.rb3
3 files changed, 15 insertions, 7 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb
index fe3df473d73..8e4de640953 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -37,7 +37,7 @@ class Environment < ActiveRecord::Base
state :stopped
end
- def recently_updated_on?(ref)
+ def recently_updated_on_branch?(ref)
ref.to_s == last_deployment.ref
end
diff --git a/app/models/project.rb b/app/models/project.rb
index d885419e0a1..297d7721abe 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1296,12 +1296,19 @@ class Project < ActiveRecord::Base
.group(:environment_id)
.select(:environment_id)
- envs = environments.available.where(id: environment_ids)
+ environments_found = environments.available
+ .where(id: environment_ids).to_a
- if commit
- envs.select { |environment| env.includes_commit?(commit) }
- else
- envs.select { |environment| env.recently_updated_on?(ref) }
+ return environments_found unless commit
+
+ environments_found.select do |environment|
+ environment.includes_commit?(commit)
+ end
+ end
+
+ def environments_recently_updated_on_branch(branch)
+ environments_for(branch).select do |environment|
+ environment.recently_updated_on_branch?(branch)
end
end
diff --git a/app/services/ci/stop_environments_service.rb b/app/services/ci/stop_environments_service.rb
index b7a49a424ce..0ffe73611c4 100644
--- a/app/services/ci/stop_environments_service.rb
+++ b/app/services/ci/stop_environments_service.rb
@@ -27,7 +27,8 @@ module Ci
end
def environments
- @environments ||= project.environments_for(@ref)
+ @environments ||= project
+ .environments_recently_updated_on_branch(@ref)
end
end
end