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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
16bfce40
Commit
16bfce40
authored
Feb 01, 2022
by
Pedro Pombeiro
Committed by
Jan Provaznik
Feb 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REST: Fix scope of /groups/:id/runners?type endpoint
Changelog: fixed
parent
3cb03505
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
24 deletions
+58
-24
app/models/ci/runner.rb
app/models/ci/runner.rb
+17
-0
doc/api/runners.md
doc/api/runners.md
+2
-4
lib/api/ci/runners.rb
lib/api/ci/runners.rb
+1
-6
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+28
-13
spec/requests/api/ci/runners_spec.rb
spec/requests/api/ci/runners_spec.rb
+10
-1
No files found.
app/models/ci/runner.rb
View file @
16bfce40
...
...
@@ -162,6 +162,23 @@ module Ci
)
end
scope
:group_or_instance_wide
,
->
(
group
)
do
group_and_ancestor_runners
=
if
::
Feature
.
enabled?
(
:ci_find_runners_by_ci_mirrors
,
group
,
default_enabled: :yaml
)
belonging_to_group_and_ancestors
(
group
.
id
)
else
legacy_belonging_to_group
(
group
.
id
,
include_ancestors:
true
)
end
from_union
(
[
group_and_ancestor_runners
,
instance_type
],
remove_duplicates:
false
)
end
scope
:assignable_for
,
->
(
project
)
do
# FIXME: That `to_sql` is needed to workaround a weird Rails bug.
# Without that, placeholders would miss one and couldn't match.
...
...
doc/api/runners.md
View file @
16bfce40
...
...
@@ -448,8 +448,7 @@ Example response:
## List project's runners
List all runners (specific and shared) available in the project. Shared runners
are listed if at least one shared runner is defined.
List all runners available in the project, including from ancestor groups and any shared runners.
```
plaintext
GET /projects/:id/runners
...
...
@@ -567,8 +566,7 @@ curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://git
## List group's runners
List all runners (specific and shared) available in the group as well it's ancestor groups.
Shared runners are listed if at least one shared runner is defined.
List all runners available in the group as well as its ancestor groups, including any shared runners.
```
plaintext
GET /groups/:id/runners
...
...
lib/api/ci/runners.rb
View file @
16bfce40
...
...
@@ -232,12 +232,7 @@ module API
use
:pagination
end
get
':id/runners'
do
runners
=
if
::
Feature
.
enabled?
(
:ci_find_runners_by_ci_mirrors
,
user_group
,
default_enabled: :yaml
)
::
Ci
::
Runner
.
belonging_to_group_and_ancestors
(
user_group
.
id
)
else
::
Ci
::
Runner
.
legacy_belonging_to_group
(
user_group
.
id
,
include_ancestors:
true
)
end
runners
=
::
Ci
::
Runner
.
group_or_instance_wide
(
user_group
)
runners
=
apply_filter
(
runners
,
params
)
present
paginate
(
runners
),
with:
Entities
::
Ci
::
Runner
...
...
spec/models/ci/runner_spec.rb
View file @
16bfce40
...
...
@@ -265,22 +265,37 @@ RSpec.describe Ci::Runner do
it_behaves_like
'.belonging_to_parent_group_of_project'
end
describe
'.owned_or_instance_wide'
do
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
,
:group
,
groups:
[
group
])
context
'with existing system wide, group and project runners'
do
# group specific
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
group:
group
)
}
let_it_be
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
# project specific
project_runner
=
create
(
:ci_runner
,
:project
,
projects:
[
project
])
# project specific
let_it_be
(
:project_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
])
}
# globally shared
shared_runner
=
create
(
:ci_runner
,
:instance
)
# globally shared
let_it_be
(
:shared_runner
)
{
create
(
:ci_runner
,
:instance
)
}
expect
(
described_class
.
owned_or_instance_wide
(
project
.
id
)).
to
contain_exactly
(
group_runner
,
project_runner
,
shared_runner
)
describe
'.owned_or_instance_wide'
do
subject
{
described_class
.
owned_or_instance_wide
(
project
.
id
)
}
it
'returns a globally shared, a project specific and a group specific runner'
do
is_expected
.
to
contain_exactly
(
group_runner
,
project_runner
,
shared_runner
)
end
end
describe
'.group_or_instance_wide'
do
subject
{
described_class
.
group_or_instance_wide
(
group
)
}
before
do
# Ensure the project runner is instantiated
project_runner
end
it
'returns a globally shared and a group specific runner'
do
is_expected
.
to
contain_exactly
(
group_runner
,
shared_runner
)
end
end
end
...
...
spec/requests/api/ci/runners_spec.rb
View file @
16bfce40
...
...
@@ -1026,7 +1026,8 @@ RSpec.describe API::Ci::Runners do
get
api
(
"/groups/
#{
group
.
id
}
/runners"
,
user
)
expect
(
json_response
).
to
match_array
([
a_hash_including
(
'description'
=>
'Group runner A'
,
'active'
=>
true
,
'paused'
=>
false
)
a_hash_including
(
'description'
=>
'Group runner A'
,
'active'
=>
true
,
'paused'
=>
false
),
a_hash_including
(
'description'
=>
'Shared runner'
,
'active'
=>
true
,
'paused'
=>
false
)
])
end
...
...
@@ -1039,6 +1040,14 @@ RSpec.describe API::Ci::Runners do
])
end
it
'returns instance runners when instance_type is specified'
do
get
api
(
"/groups/
#{
group
.
id
}
/runners?type=instance_type"
,
user
)
expect
(
json_response
).
to
match_array
([
a_hash_including
(
'description'
=>
'Shared runner'
)
])
end
it
'returns empty result when type does not match'
do
get
api
(
"/groups/
#{
group
.
id
}
/runners?type=project_type"
,
user
)
...
...
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