Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
295184f6
Commit
295184f6
authored
Mar 01, 2017
by
Alexis Reigel
Committed by
Alexis Reigel
Apr 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include group runners in scope
parent
9a07bc81
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
6 deletions
+75
-6
app/models/ci/runner.rb
app/models/ci/runner.rb
+29
-2
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+46
-4
No files found.
app/models/ci/runner.rb
View file @
295184f6
...
...
@@ -14,6 +14,8 @@ module Ci
has_many
:builds
has_many
:runner_projects
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:projects
,
through: :runner_projects
has_many
:runner_groups
has_many
:groups
,
through: :runner_groups
has_one
:last_build
,
->
()
{
order
(
'id DESC'
)
},
class_name:
'Ci::Build'
...
...
@@ -27,8 +29,33 @@ module Ci
scope
:ordered
,
->
()
{
order
(
id: :desc
)
}
scope
:owned_or_shared
,
->
(
project_id
)
do
joins
(
'LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'
)
.
where
(
"ci_runner_projects.project_id = :project_id OR ci_runners.is_shared = true"
,
project_id:
project_id
)
joins
(
%{
-- project runners
LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id
-- group runners
LEFT JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
LEFT JOIN namespaces ON namespaces.id = ci_runner_groups.group_id
LEFT JOIN projects group_projects ON group_projects.namespace_id = namespaces.id
}
).
where
(
%{
-- project runners
ci_runner_projects.project_id = :project_id
OR
-- group runners
group_projects.id = :project_id
OR
-- shared runners
ci_runners.is_shared = true
}
,
project_id:
project_id
)
end
scope
:assignable_for
,
->
(
project
)
do
...
...
spec/models/ci/runner_spec.rb
View file @
295184f6
...
...
@@ -52,19 +52,61 @@ describe Ci::Runner do
describe
'scopes'
do
describe
'owned_or_shared'
do
it
'returns the specific project runner'
do
# own
specific_project
=
create
:project
other_project
=
create
:project
specific_runner
=
create
:ci_runner
,
:specific
,
projects:
[
specific_project
]
other_runner
=
create
:ci_runner
,
:specific
,
projects:
[
other_project
]
# other
other_project
=
create
:project
create
:ci_runner
,
:specific
,
projects:
[
other_project
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
it
'returns the shared projects'
do
runner
=
create
:ci_runner
,
:shared
it
'returns the shared project runner'
do
project
=
create
:project
runner
=
create
:ci_runner
,
:shared
,
projects:
[
project
]
expect
(
described_class
.
owned_or_shared
(
0
)).
to
eq
[
runner
]
end
it
'returns the specific group runner'
do
# own
specific_group
=
create
:group
specific_project
=
create
:project
,
group:
specific_group
specific_runner
=
create
:ci_runner
,
:specific
,
groups:
[
specific_group
]
# other
other_group
=
create
:group
create
:project
,
group:
other_group
create
:ci_runner
,
:specific
,
groups:
[
other_group
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
it
'returns the shared group runner'
do
group
=
create
:group
runner
=
create
:ci_runner
,
:shared
,
groups:
[
group
]
expect
(
described_class
.
owned_or_shared
(
0
)).
to
eq
[
runner
]
end
it
'returns a globally shared, a project specific and a group specific runner'
do
# group specific
group
=
create
:group
project
=
create
:project
,
group:
group
group_runner
=
create
:ci_runner
,
:specific
,
groups:
[
group
]
# project specific
project_runner
=
create
:ci_runner
,
:specific
,
projects:
[
project
]
# globally shared
shared_runner
=
create
:ci_runner
,
:shared
expect
(
described_class
.
owned_or_shared
(
project
.
id
)).
to
match_array
[
group_runner
,
project_runner
,
shared_runner
]
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment