Merge branch 'support-project-security-dashboard' into 'master'
Backport support project security dashboard changes See merge request gitlab-org/gitlab-ce!22824
This commit is contained in:
commit
6e9179ab46
2 changed files with 19 additions and 5 deletions
|
@ -181,22 +181,31 @@ module Ci
|
|||
#
|
||||
# ref - The name (or names) of the branch(es)/tag(s) to limit the list of
|
||||
# pipelines to.
|
||||
def self.newest_first(ref = nil)
|
||||
# limit - This limits a backlog search, default to 100.
|
||||
def self.newest_first(ref: nil, limit: 100)
|
||||
relation = order(id: :desc)
|
||||
relation = relation.where(ref: ref) if ref
|
||||
|
||||
ref ? relation.where(ref: ref) : relation
|
||||
if limit
|
||||
ids = relation.limit(limit).select(:id)
|
||||
# MySQL does not support limit in subquery
|
||||
ids = ids.pluck(:id) if Gitlab::Database.mysql?
|
||||
relation = relation.where(id: ids)
|
||||
end
|
||||
|
||||
relation
|
||||
end
|
||||
|
||||
def self.latest_status(ref = nil)
|
||||
newest_first(ref).pluck(:status).first
|
||||
newest_first(ref: ref).pluck(:status).first
|
||||
end
|
||||
|
||||
def self.latest_successful_for(ref)
|
||||
newest_first(ref).success.take
|
||||
newest_first(ref: ref).success.take
|
||||
end
|
||||
|
||||
def self.latest_successful_for_refs(refs)
|
||||
relation = newest_first(refs).success
|
||||
relation = newest_first(ref: refs).success
|
||||
|
||||
relation.each_with_object({}) do |pipeline, hash|
|
||||
hash[pipeline.ref] ||= pipeline
|
||||
|
|
|
@ -1043,6 +1043,11 @@ describe Ci::Pipeline, :mailer do
|
|||
expect(described_class.newest_first.pluck(:status))
|
||||
.to eq(%w[skipped failed success canceled])
|
||||
end
|
||||
|
||||
it 'searches limited backlog' do
|
||||
expect(described_class.newest_first(limit: 1).pluck(:status))
|
||||
.to eq(%w[skipped])
|
||||
end
|
||||
end
|
||||
|
||||
describe '.latest_status' do
|
||||
|
|
Loading…
Reference in a new issue