Commit 9b836b83 authored by Alexis Reigel's avatar Alexis Reigel

support group hierarchies for group runners

parent 6bd3cb04
...@@ -31,13 +31,10 @@ module Ci ...@@ -31,13 +31,10 @@ module Ci
joins(:runner_projects).where(ci_runner_projects: { project_id: project_id }) joins(:runner_projects).where(ci_runner_projects: { project_id: project_id })
} }
scope :belonging_to_group, -> (project_id) { scope :belonging_to_group, -> (project_id) {
joins( project_groups = ::Group.joins(:projects).where(projects: { id: project_id })
%{ hierarchy_groups = Gitlab::GroupHierarchy.new(project_groups).base_and_ancestors
INNER JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
INNER JOIN namespaces ON namespaces.id = ci_runner_groups.group_id joins(:groups).where(namespaces: { id: hierarchy_groups })
INNER JOIN projects ON projects.namespace_id = namespaces.id
}
).where('projects.id = :project_id', project_id: project_id)
} }
scope :owned_or_shared, -> (project_id) do scope :owned_or_shared, -> (project_id) do
......
...@@ -93,6 +93,15 @@ describe Ci::Runner do ...@@ -93,6 +93,15 @@ describe Ci::Runner do
expect(described_class.belonging_to_group(specific_project.id)).to eq [specific_runner] expect(described_class.belonging_to_group(specific_project.id)).to eq [specific_runner]
end end
it 'returns the group runner from a parent group' do
parent_group = create :group
group = create :group, parent: parent_group
project = create :project, group: group
runner = create :ci_runner, :specific, groups: [parent_group]
expect(described_class.belonging_to_group(project.id)).to eq [runner]
end
end end
describe '.owned_or_shared' do describe '.owned_or_shared' do
......
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