Commit 1109c227 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ce-fix_vuln_list_on_group_dashboard' into 'master'

Backport generic methods to CE

See merge request gitlab-org/gitlab-ce!22826
parents 836ab5f7 a89fb014
...@@ -238,6 +238,10 @@ module Ci ...@@ -238,6 +238,10 @@ module Ci
end end
end end
def self.latest_successful_ids_per_project
success.group(:project_id).select('max(id) as id')
end
def self.truncate_sha(sha) def self.truncate_sha(sha)
sha[0...8] sha[0...8]
end end
......
...@@ -232,6 +232,12 @@ class Namespace < ActiveRecord::Base ...@@ -232,6 +232,12 @@ class Namespace < ActiveRecord::Base
Project.inside_path(full_path) Project.inside_path(full_path)
end end
# Includes pipelines from this namespace and pipelines from all subgroups
# that belongs to this namespace
def all_pipelines
Ci::Pipeline.where(project: all_projects)
end
def has_parent? def has_parent?
parent.present? parent.present?
end end
......
...@@ -1148,6 +1148,19 @@ describe Ci::Pipeline, :mailer do ...@@ -1148,6 +1148,19 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '.latest_successful_ids_per_project' do
let(:projects) { create_list(:project, 2) }
let!(:pipeline1) { create(:ci_pipeline, :success, project: projects[0]) }
let!(:pipeline2) { create(:ci_pipeline, :success, project: projects[0]) }
let!(:pipeline3) { create(:ci_pipeline, :failed, project: projects[0]) }
let!(:pipeline4) { create(:ci_pipeline, :success, project: projects[1]) }
it 'returns expected pipeline ids' do
expect(described_class.latest_successful_ids_per_project)
.to contain_exactly(pipeline2, pipeline4)
end
end
describe '.internal_sources' do describe '.internal_sources' do
subject { described_class.internal_sources } subject { described_class.internal_sources }
......
...@@ -562,6 +562,17 @@ describe Namespace do ...@@ -562,6 +562,17 @@ describe Namespace do
it { expect(group.all_projects.to_a).to match_array([project2, project1]) } it { expect(group.all_projects.to_a).to match_array([project2, project1]) }
end end
describe '#all_pipelines' do
let(:group) { create(:group) }
let(:child) { create(:group, parent: group) }
let!(:project1) { create(:project_empty_repo, namespace: group) }
let!(:project2) { create(:project_empty_repo, namespace: child) }
let!(:pipeline1) { create(:ci_empty_pipeline, project: project1) }
let!(:pipeline2) { create(:ci_empty_pipeline, project: project2) }
it { expect(group.all_pipelines.to_a).to match_array([pipeline1, pipeline2]) }
end
describe '#share_with_group_lock with subgroups', :nested_groups do describe '#share_with_group_lock with subgroups', :nested_groups do
context 'when creating a subgroup' do context 'when creating a subgroup' do
let(:subgroup) { create(:group, parent: root_group )} let(:subgroup) { create(:group, parent: root_group )}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment