summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-11-07 23:44:11 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-11-08 00:04:18 +0800
commit18a71c47603d703de73c46fef4889887f685bebe (patch)
tree591a9bbe4fc7f1adcae5e26b52a1ef625ee6e016 /app/models
parent7ce03197d33e1194bed49fbd9ac7778f72d6fada (diff)
downloadgitlab-ce-18a71c47603d703de73c46fef4889887f685bebe.tar.gz
Show commit status from latest pipeline
Rather than compound status from all pipelines. Closes #20560
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/pipeline.rb6
-rw-r--r--app/models/commit.rb16
2 files changed, 14 insertions, 8 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index d3432632899..3ab19938c0f 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -83,9 +83,13 @@ module Ci
end
end
+ scope :latest, -> { order(id: :desc) }
+
# ref can't be HEAD or SHA, can only be branch/tag name
+ scope :latest_for, ->(ref) { where(ref: ref).latest }
+
def self.latest_successful_for(ref)
- where(ref: ref).order(id: :desc).success.first
+ latest_for(ref).success.first
end
def self.truncate_sha(sha)
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 9e7fde9503d..2134ba2d75f 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -232,13 +232,15 @@ class Commit
def status(ref = nil)
@statuses ||= {}
- if @statuses.key?(ref)
- @statuses[ref]
- elsif ref
- @statuses[ref] = pipelines.where(ref: ref).status
- else
- @statuses[ref] = pipelines.status
- end
+ return @statuses[ref] if @statuses.key?(ref)
+
+ latest_pipeline = if ref
+ pipelines.latest_for(ref)
+ else
+ pipelines.latest
+ end.first
+
+ @statuses[ref] = latest_pipeline.try(:status)
end
def revert_branch_name