summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2016-12-24 07:16:30 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2016-12-24 07:16:30 +0000
commit52a259dd84031819bc24638963ea1a12fe56fd30 (patch)
tree63fb2b024f79de7d9abbb4f3d12cf6cf93f9afd7
parent1c3c5c2bbda09d43a034d665cfacfd0c4f334f45 (diff)
downloadgitlab-ce-52a259dd84031819bc24638963ea1a12fe56fd30.tar.gz
Revert "Merge branch 'fix-latest-pipeine-ordering' into 'master'"
This reverts merge request !8286
-rw-r--r--app/models/ci/pipeline.rb7
-rw-r--r--app/models/project.rb2
-rw-r--r--changelogs/unreleased/fix-latest-pipeine-ordering.yml4
-rw-r--r--spec/models/ci/pipeline_spec.rb14
4 files changed, 14 insertions, 13 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 6894a5763ff..f2f6453b3b9 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -93,8 +93,11 @@ module Ci
.select("max(#{quoted_table_name}.id)")
.group(:ref, :sha)
- relation = ref ? where(ref: ref) : self
- relation.where(id: max_id).order(id: :desc)
+ if ref
+ where(id: max_id, ref: ref)
+ else
+ where(id: max_id)
+ end
end
def self.latest_status(ref = nil)
diff --git a/app/models/project.rb b/app/models/project.rb
index 72fdd4514c4..26fa20f856d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -418,7 +418,7 @@ class Project < ActiveRecord::Base
repository.commit(ref)
end
- # ref can't be HEAD or SHA, can only be branch/tag name
+ # ref can't be HEAD, can only be branch/tag name or SHA
def latest_successful_builds_for(ref = default_branch)
latest_pipeline = pipelines.latest_successful_for(ref)
diff --git a/changelogs/unreleased/fix-latest-pipeine-ordering.yml b/changelogs/unreleased/fix-latest-pipeine-ordering.yml
deleted file mode 100644
index 3dbd1ba036a..00000000000
--- a/changelogs/unreleased/fix-latest-pipeine-ordering.yml
+++ /dev/null
@@ -1,4 +0,0 @@
----
-title: Fix finding the latest pipeline
-merge_request: 8286
-author:
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index b28da6daabf..dc377d15f15 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -424,18 +424,20 @@ describe Ci::Pipeline, models: true do
context 'when no ref is specified' do
let(:pipelines) { described_class.latest.all }
- it 'gives the latest pipelines for the same ref and different sha in reverse chronological order' do
- expect(pipelines.map(&:sha)).to eq(%w[C B A])
- expect(pipelines.map(&:status)).to eq(%w[skipped failed success])
+ it 'returns the latest pipeline for the same ref and different sha' do
+ expect(pipelines.map(&:sha)).to contain_exactly('A', 'B', 'C')
+ expect(pipelines.map(&:status)).
+ to contain_exactly('success', 'failed', 'skipped')
end
end
context 'when ref is specified' do
let(:pipelines) { described_class.latest('ref').all }
- it 'gives the latest pipelines for ref and different sha in reverse chronological order' do
- expect(pipelines.map(&:sha)).to eq(%w[B A])
- expect(pipelines.map(&:status)).to eq(%w[failed success])
+ it 'returns the latest pipeline for ref and different sha' do
+ expect(pipelines.map(&:sha)).to contain_exactly('A', 'B')
+ expect(pipelines.map(&:status)).
+ to contain_exactly('success', 'failed')
end
end
end