diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:56:38 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:56:38 +0100 |
commit | 778b5a5a04c4861c84408c944fa8dc01411cbf55 (patch) | |
tree | 04027e55d3dfdfb35c521577c8f28db09a394ee6 /app/models/project.rb | |
parent | 166ee0965bacc20e2ad1187321654499a9b0f825 (diff) | |
parent | da57eb39cd2e5d8dd92b05d16f49681f1677f3e8 (diff) | |
download | gitlab-ce-778b5a5a04c4861c84408c944fa8dc01411cbf55.tar.gz |
Merge remote-tracking branch 'origin/master' into zj-slash-commands-mattermost
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index c5acae99c4c..fdaa973098a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1326,22 +1326,30 @@ class Project < ActiveRecord::Base Gitlab::Redis.with { |redis| redis.del(pushes_since_gc_redis_key) } end - def environments_for(ref, commit, with_tags: false) - environment_ids = deployments.group(:environment_id). - select(:environment_id) + def environments_for(ref, commit: nil, with_tags: false) + deployments_query = with_tags ? 'ref = ? OR tag IS TRUE' : 'ref = ?' - environment_ids = - if with_tags - environment_ids.where('ref=? OR tag IS TRUE', ref) - else - environment_ids.where(ref: ref) - end + environment_ids = deployments + .where(deployments_query, ref.to_s) + .group(:environment_id) + .select(:environment_id) + + environments_found = environments.available + .where(id: environment_ids).to_a + + return environments_found unless commit - environments.available.where(id: environment_ids).select do |environment| + 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 + private def pushes_since_gc_redis_key |