Skip to content

Commit 36e7ffe

Browse files
committed
Fix runners filtering
1 parent 97c8896 commit 36e7ffe

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/api/runners.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Runners < Grape::API
99
# Example Request:
1010
# GET /runners
1111
get do
12-
runners = filter_runners(current_user.ci_authorized_runners, params[:scope])
12+
runners = filter_runners(current_user.ci_authorized_runners, params[:scope], without: ['specific', 'shared'])
1313
present paginate(runners), with: Entities::Runner
1414
end
1515

@@ -124,10 +124,14 @@ class Runners < Grape::API
124124
end
125125

126126
helpers do
127-
def filter_runners(runners, scope)
127+
def filter_runners(runners, scope, options = {})
128128
return runners unless scope.present?
129129

130130
available_scopes = ::Ci::Runner::AVAILABLE_SCOPES
131+
if options[:without]
132+
available_scopes = available_scopes - options[:without]
133+
end
134+
131135
if (available_scopes & [scope]).empty?
132136
render_api_error!('Scope contains invalid value', 400)
133137
end

spec/requests/api/runners_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
end
3434

3535
it 'should filter runners by scope' do
36-
get api('/runners?scope=specific', user)
36+
get api('/runners?scope=active', user)
3737
shared = false || json_response.map{ |r| r['is_shared'] }.inject{ |sum, shr| sum || shr}
3838

3939
expect(response.status).to eq(200)
@@ -78,7 +78,7 @@
7878
end
7979

8080
it 'should filter runners by scope' do
81-
get api('/runners?scope=specific', admin)
81+
get api('/runners/all?scope=specific', admin)
8282
shared = false || json_response.map{ |r| r['is_shared'] }.inject{ |sum, shr| sum || shr}
8383

8484
expect(response.status).to eq(200)

0 commit comments

Comments
 (0)