summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-02-16 22:17:42 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-02-20 15:57:03 +0800
commit3750b06b8cdc02bc87eba27dd8e4ab5f1f24802f (patch)
tree4d1c6cca34c4ac02f7f04dfc1f6e537ee957b924
parentd38fb942e188021d7def5eb577a73c82b8e5e66d (diff)
downloadgitlab-ce-3750b06b8cdc02bc87eba27dd8e4ab5f1f24802f.tar.gz
Consider the case where we don't specify ref for pipeline
-rw-r--r--app/models/ci/pipeline.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 2a987bfa87b..6e89b18aee5 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -91,11 +91,13 @@ module Ci
scope :latest, ->(ref = nil) do
max_id = unscope(:select)
.select("max(#{quoted_table_name}.id)")
- .where(ref: ref)
.group(:ref, :sha)
- relation = ref ? where(ref: ref) : self
- relation.where(id: max_id)
+ if ref
+ where(ref: ref, id: max_id.where(ref: ref))
+ else
+ where(id: max_id)
+ end
end
def self.latest_status(ref = nil)