Merge branch 'fix-latest-pipeine-ordering' into 'master'
Fix code that selects latest pipelines Closes #25993 and #26031 See merge request !8286
This commit is contained in:
commit
5c0f25410c
4 changed files with 13 additions and 14 deletions
|
@ -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).order(id: :desc)
|
||||
end
|
||||
|
||||
def self.latest_status(ref = nil)
|
||||
|
|
|
@ -418,7 +418,7 @@ class Project < ActiveRecord::Base
|
|||
repository.commit(ref)
|
||||
end
|
||||
|
||||
# ref can't be HEAD, can only be branch/tag name or SHA
|
||||
# ref can't be HEAD or SHA, can only be branch/tag name
|
||||
def latest_successful_builds_for(ref = default_branch)
|
||||
latest_pipeline = pipelines.latest_successful_for(ref)
|
||||
|
||||
|
|
4
changelogs/unreleased/fix-latest-pipeine-ordering.yml
Normal file
4
changelogs/unreleased/fix-latest-pipeine-ordering.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Fix finding the latest pipeline
|
||||
merge_request: 8286
|
||||
author:
|
|
@ -424,20 +424,18 @@ describe Ci::Pipeline, models: true do
|
|||
context 'when no ref is specified' do
|
||||
let(:pipelines) { described_class.latest.all }
|
||||
|
||||
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')
|
||||
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])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ref is specified' do
|
||||
let(:pipelines) { described_class.latest('ref').all }
|
||||
|
||||
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')
|
||||
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])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue