Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2016-12-27 02:14:39 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2016-12-27 02:14:39 +0300
commit796b5b575fe9ce54a4bee26cf389f135313e4d41 (patch)
tree1d69f915ce4eec7b007bd8d59ede2cb06a1f01f5
parentf8bab6108ee80f46863721c41c33f10ee635dc41 (diff)
parente60bf0d6c895bd16919bf22da0829055845574e4 (diff)
Merge branch 'fix-latest-pipeine-ordering-again' into 'master'
Order only for latest_successful_for See merge request !8301
-rw-r--r--app/models/ci/pipeline.rb9
-rw-r--r--changelogs/unreleased/fix-latest-pipeine-ordering.yml4
-rw-r--r--spec/models/ci/pipeline_spec.rb13
3 files changed, 20 insertions, 6 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index f2f6453b3b9..abbbddaa4f6 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -93,11 +93,8 @@ module Ci
.select("max(#{quoted_table_name}.id)")
.group(:ref, :sha)
- if ref
- where(id: max_id, ref: ref)
- else
- where(id: max_id)
- end
+ relation = ref ? where(ref: ref) : self
+ relation.where(id: max_id)
end
def self.latest_status(ref = nil)
@@ -105,7 +102,7 @@ module Ci
end
def self.latest_successful_for(ref)
- success.latest(ref).first
+ success.latest(ref).order(id: :desc).first
end
def self.truncate_sha(sha)
diff --git a/changelogs/unreleased/fix-latest-pipeine-ordering.yml b/changelogs/unreleased/fix-latest-pipeine-ordering.yml
new file mode 100644
index 00000000000..b155d51741b
--- /dev/null
+++ b/changelogs/unreleased/fix-latest-pipeine-ordering.yml
@@ -0,0 +1,4 @@
+---
+title: Fix finding the latest pipeline
+merge_request: 8301
+author:
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index dc377d15f15..cebaa157ef3 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -464,6 +464,19 @@ describe Ci::Pipeline, models: true do
end
end
+ describe '.latest_successful_for' do
+ include_context 'with some outdated pipelines'
+
+ let!(:latest_successful_pipeline) do
+ create_pipeline(:success, 'ref', 'D')
+ end
+
+ it 'returns the latest successful pipeline' do
+ expect(described_class.latest_successful_for('ref')).
+ to eq(latest_successful_pipeline)
+ end
+ end
+
describe '#status' do
let!(:build) { create(:ci_build, :created, pipeline: pipeline, name: 'test') }