diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-01-07 13:37:33 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-01-07 13:37:33 +0000 |
commit | cd11ede9ccdb05ff3e91bb4507af1ff063722608 (patch) | |
tree | fd27408bfa0afc1c11e7b6f34496815304291572 /app/models/ci | |
parent | 75e6561684415b2fffb47a6293ba787c379b84b7 (diff) | |
parent | 4ab0b33db6f328fc68394fd3af992052f883401e (diff) | |
download | gitlab-ce-cd11ede9ccdb05ff3e91bb4507af1ff063722608.tar.gz |
Merge branch 'user-update-head-pipeline-worker-2' into 'master'
Refactor the logic of updating head pipelines for merge requests
See merge request gitlab-org/gitlab-ce!23502
Diffstat (limited to 'app/models/ci')
-rw-r--r-- | app/models/ci/pipeline.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index d0027ad823c..30a957b4117 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -178,6 +178,15 @@ module Ci scope :for_user, -> (user) { where(user: user) } + scope :for_merge_request, -> (merge_request, ref, sha) do + ## + # We have to filter out unrelated MR pipelines. + # When merge request is empty, it selects general pipelines, such as push sourced pipelines. + # When merge request is matched, it selects MR pipelines. + where(merge_request: [nil, merge_request], ref: ref, sha: sha) + .sort_by_merge_request_pipelines + end + # Returns the pipelines in descending order (= newest first), optionally # limited to a number of references. # @@ -265,6 +274,10 @@ module Ci sources.reject { |source| source == "external" }.values end + def self.latest_for_merge_request(merge_request, ref, sha) + for_merge_request(merge_request, ref, sha).first + end + def self.ci_sources_values config_sources.values_at(:repository_source, :auto_devops_source, :unknown_source) end |