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
Léo-Paul Géneau
gitlab-ce
Commits
d6167a92
Commit
d6167a92
authored
Oct 04, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split up Ci::Runner.owned_or_shared scope
parent
81c0c57a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
34 deletions
+40
-34
app/models/ci/runner.rb
app/models/ci/runner.rb
+16
-16
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+24
-18
No files found.
app/models/ci/runner.rb
View file @
d6167a92
...
@@ -21,17 +21,17 @@ module Ci
...
@@ -21,17 +21,17 @@ module Ci
before_validation
:set_default_values
before_validation
:set_default_values
scope
:specific
,
->
()
{
where
(
is_shared:
false
)
}
scope
:specific
,
->
{
where
(
is_shared:
false
)
}
scope
:shared
,
->
()
{
where
(
is_shared:
true
)
}
scope
:shared
,
->
{
where
(
is_shared:
true
)
}
scope
:active
,
->
()
{
where
(
active:
true
)
}
scope
:active
,
->
{
where
(
active:
true
)
}
scope
:paused
,
->
()
{
where
(
active:
false
)
}
scope
:paused
,
->
{
where
(
active:
false
)
}
scope
:online
,
->
()
{
where
(
'contacted_at > ?'
,
contact_time_deadline
)
}
scope
:online
,
->
{
where
(
'contacted_at > ?'
,
contact_time_deadline
)
}
scope
:ordered
,
->
()
{
order
(
id: :desc
)
}
scope
:ordered
,
->
{
order
(
id: :desc
)
}
scope
:belonging_to_project
,
->
(
project_id
)
{
scope
:owned_or_shared
,
->
(
project_id
)
do
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
project_runners
=
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
}
scope
:belonging_to_group
,
->
(
project_id
)
{
group_runners
=
joins
(
joins
(
%{
%{
INNER JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
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
INNER JOIN namespaces ON namespaces.id = ci_runner_groups.group_id
...
@@ -43,13 +43,13 @@ module Ci
...
@@ -43,13 +43,13 @@ module Ci
AND
AND
projects.group_runners_enabled = :true
projects.group_runners_enabled = :true
}
,
}
,
project_id:
project_id
,
project_id:
project_id
,
true:
true
true:
true
)
)
}
shared_runners
=
where
(
is_shared:
true
)
scope
:owned_or_shared
,
->
(
project_id
)
do
union
=
Gitlab
::
SQL
::
Union
.
new
([
belonging_to_project
(
project_id
),
belonging_to_group
(
project_id
),
shared
])
union
=
Gitlab
::
SQL
::
Union
.
new
([
project_runners
,
group_runners
,
shared_runners
])
from
(
"(
#{
union
.
to_sql
}
) ci_runners"
)
from
(
"(
#{
union
.
to_sql
}
) ci_runners"
)
end
end
...
...
spec/models/ci/runner_spec.rb
View file @
d6167a92
...
@@ -49,7 +49,23 @@ describe Ci::Runner do
...
@@ -49,7 +49,23 @@ describe Ci::Runner do
end
end
end
end
describe
'.owned_or_shared'
do
describe
'.shared'
do
it
'returns the shared group runner'
do
group
=
create
:group
runner
=
create
:ci_runner
,
:shared
,
groups:
[
group
]
expect
(
described_class
.
shared
).
to
eq
[
runner
]
end
it
'returns the shared project runner'
do
project
=
create
:project
runner
=
create
:ci_runner
,
:shared
,
projects:
[
project
]
expect
(
described_class
.
shared
).
to
eq
[
runner
]
end
end
describe
'.belonging_to_project'
do
it
'returns the specific project runner'
do
it
'returns the specific project runner'
do
# own
# own
specific_project
=
create
:project
specific_project
=
create
:project
...
@@ -59,16 +75,11 @@ describe Ci::Runner do
...
@@ -59,16 +75,11 @@ describe Ci::Runner do
other_project
=
create
:project
other_project
=
create
:project
create
:ci_runner
,
:specific
,
projects:
[
other_project
]
create
:ci_runner
,
:specific
,
projects:
[
other_project
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
expect
(
described_class
.
belonging_to_project
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
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
end
end
describe
'.belonging_to_group'
do
it
'returns the specific group runner'
do
it
'returns the specific group runner'
do
# own
# own
specific_group
=
create
:group
specific_group
=
create
:group
...
@@ -80,7 +91,7 @@ describe Ci::Runner do
...
@@ -80,7 +91,7 @@ describe Ci::Runner do
create
:project
,
group:
other_group
create
:project
,
group:
other_group
create
:ci_runner
,
:specific
,
groups:
[
other_group
]
create
:ci_runner
,
:specific
,
groups:
[
other_group
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
expect
(
described_class
.
belonging_to_group
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
end
it
'does not return the group runner if the project has group runners disabled'
do
it
'does not return the group runner if the project has group runners disabled'
do
...
@@ -88,16 +99,11 @@ describe Ci::Runner do
...
@@ -88,16 +99,11 @@ describe Ci::Runner do
specific_project
=
create
:project
,
group:
specific_group
,
group_runners_enabled:
false
specific_project
=
create
:project
,
group:
specific_group
,
group_runners_enabled:
false
create
:ci_runner
,
:specific
,
groups:
[
specific_group
]
create
:ci_runner
,
:specific
,
groups:
[
specific_group
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
be_empty
expect
(
described_class
.
belonging_to_group
(
specific_project
.
id
)).
to
be_empty
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
end
end
describe
'.owned_or_shared'
do
it
'returns a globally shared, a project specific and a group specific runner'
do
it
'returns a globally shared, a project specific and a group specific runner'
do
# group specific
# group specific
group
=
create
:group
group
=
create
:group
...
...
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