Commit 15c1c5be authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '341114-fj-remove-runner-ancestors-scope' into 'master'

Enable Runner ancestor scopes

See merge request gitlab-org/gitlab!74991
parents b819e1f9 11d49cd2
......@@ -81,14 +81,7 @@ module Ci
scope :belonging_to_group, -> (group_id, include_ancestors: false) {
groups = ::Group.where(id: group_id)
if include_ancestors
groups = if Feature.enabled?(:linear_runner_ancestor_scopes, default_enabled: :yaml)
groups.self_and_ancestors
else
Gitlab::ObjectHierarchy.new(groups).base_and_ancestors
end
end
groups = groups.self_and_ancestors if include_ancestors
joins(:runner_namespaces)
.where(ci_runner_namespaces: { namespace_id: groups })
......@@ -109,14 +102,9 @@ module Ci
scope :belonging_to_parent_group_of_project, -> (project_id) {
project_groups = ::Group.joins(:projects).where(projects: { id: project_id })
hierarchy_groups = if Feature.enabled?(:linear_runner_ancestor_scopes, default_enabled: :yaml)
project_groups.self_and_ancestors.as_ids
else
Gitlab::ObjectHierarchy.new(project_groups).base_and_ancestors
end
joins(:groups)
.where(namespaces: { id: hierarchy_groups })
.where(namespaces: { id: project_groups.self_and_ancestors.as_ids })
.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/336433')
}
......
---
name: linear_runner_ancestor_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70385
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/341114
milestone: '14.6'
type: development
group: group::access
default_enabled: false
......@@ -204,38 +204,26 @@ RSpec.describe Ci::Runner do
end
describe '.belonging_to_parent_group_of_project' do
shared_examples 'returns parent group project runners' do
let(:project) { create(:project, group: group) }
let(:group) { create(:group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) }
let!(:unrelated_group) { create(:group) }
let!(:unrelated_project) { create(:project, group: unrelated_group) }
let!(:unrelated_runner) { create(:ci_runner, :group, groups: [unrelated_group]) }
it 'returns the specific group runner' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
context 'with a parent group with a runner' do
let(:runner) { create(:ci_runner, :group, groups: [parent_group]) }
let(:project) { create(:project, group: group) }
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:group) { create(:group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) }
let!(:unrelated_group) { create(:group) }
let!(:unrelated_project) { create(:project, group: unrelated_group) }
let!(:unrelated_runner) { create(:ci_runner, :group, groups: [unrelated_group]) }
it 'returns the group runner from the parent group' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
end
it 'returns the specific group runner' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
it_behaves_like 'returns parent group project runners'
context 'with a parent group with a runner' do
let(:runner) { create(:ci_runner, :group, groups: [parent_group]) }
let(:project) { create(:project, group: group) }
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
context 'when feature flag :linear_runner_ancestor_scopes is disabled' do
before do
stub_feature_flags(linear_runner_ancestor_scopes: false)
it 'returns the group runner from the parent group' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
it_behaves_like 'returns parent group project runners'
end
end
......
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