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
13a902a9
Commit
13a902a9
authored
Nov 27, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactorize jobs finding logic
parent
9d27ce16
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
10 deletions
+67
-10
app/finders/runner_jobs_finder.rb
app/finders/runner_jobs_finder.rb
+22
-0
lib/api/runners.rb
lib/api/runners.rb
+2
-6
spec/finders/runner_jobs_finder_spec.rb
spec/finders/runner_jobs_finder_spec.rb
+39
-0
spec/requests/api/runners_spec.rb
spec/requests/api/runners_spec.rb
+4
-4
No files found.
app/finders/runner_jobs_finder.rb
0 → 100644
View file @
13a902a9
class
RunnerJobsFinder
attr_reader
:runner
,
:params
def
initialize
(
runner
,
params
=
{})
@runner
=
runner
@params
=
params
end
def
execute
items
=
@runner
.
builds
items
=
by_status
(
items
)
items
end
private
def
by_status
(
items
)
return
items
unless
HasStatus
::
AVAILABLE_STATUSES
.
include?
(
params
[
:status
])
items
.
where
(
status:
params
[
:status
])
end
end
lib/api/runners.rb
View file @
13a902a9
...
@@ -90,18 +90,14 @@ module API
...
@@ -90,18 +90,14 @@ module API
end
end
params
do
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
optional
:status
,
type:
String
,
desc:
'Status of
job'
optional
:status
,
type:
String
,
desc:
'Status of
the job'
,
values:
Ci
::
Build
::
AVAILABLE_STATUSES
use
:pagination
use
:pagination
end
end
get
':id/jobs'
do
get
':id/jobs'
do
runner
=
get_runner
(
params
[
:id
])
runner
=
get_runner
(
params
[
:id
])
authenticate_list_runners_jobs!
(
runner
)
authenticate_list_runners_jobs!
(
runner
)
jobs
=
runner
.
builds
jobs
=
RunnerJobsFinder
.
new
(
runner
,
params
).
execute
if
params
[
:status
]
not_found!
(
'Status'
)
unless
Ci
::
Build
::
AVAILABLE_STATUSES
.
include?
(
params
[
:status
])
jobs
=
jobs
.
where
(
status:
params
[
:status
].
to_sym
)
end
present
paginate
(
jobs
),
with:
Entities
::
JobBasicWithProject
present
paginate
(
jobs
),
with:
Entities
::
JobBasicWithProject
end
end
...
...
spec/finders/runner_jobs_finder_spec.rb
0 → 100644
View file @
13a902a9
require
'spec_helper'
describe
RunnerJobsFinder
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:shared
)
}
subject
{
described_class
.
new
(
runner
,
params
).
execute
}
describe
'#execute'
do
context
'when params is empty'
do
let
(
:params
)
{
{}
}
let!
(
:job
)
{
create
(
:ci_build
,
runner:
runner
,
project:
project
)
}
let!
(
:job1
)
{
create
(
:ci_build
,
project:
project
)
}
it
'returns all jobs assigned to Runner'
do
is_expected
.
to
match_array
(
job
)
is_expected
.
not_to
match_array
(
job1
)
end
end
context
'when params contains status'
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target_status
|
context
"when status is
#{
target_status
}
"
do
let
(
:params
)
{
{
status:
target_status
}
}
let!
(
:job
)
{
create
(
:ci_build
,
runner:
runner
,
project:
project
,
status:
target_status
)
}
before
do
exception_status
=
HasStatus
::
AVAILABLE_STATUSES
-
[
target_status
]
create
(
:ci_build
,
runner:
runner
,
project:
project
,
status:
exception_status
.
first
)
end
it
'returns matched job'
do
is_expected
.
to
eq
([
job
])
end
end
end
end
end
end
spec/requests/api/runners_spec.rb
View file @
13a902a9
...
@@ -401,10 +401,10 @@ describe API::Runners do
...
@@ -401,10 +401,10 @@ describe API::Runners do
end
end
context
'when invalid status is provided'
do
context
'when invalid status is provided'
do
it
'return 40
4
'
do
it
'return 40
0
'
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs?status=non-existing"
,
admin
)
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs?status=non-existing"
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
40
4
)
expect
(
response
).
to
have_gitlab_http_status
(
40
0
)
end
end
end
end
end
end
...
@@ -454,10 +454,10 @@ describe API::Runners do
...
@@ -454,10 +454,10 @@ describe API::Runners do
end
end
context
'when invalid status is provided'
do
context
'when invalid status is provided'
do
it
'return 40
4
'
do
it
'return 40
0
'
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs?status=non-existing"
,
user
)
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs?status=non-existing"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
40
4
)
expect
(
response
).
to
have_gitlab_http_status
(
40
0
)
end
end
end
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