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
3e4624f6
Commit
3e4624f6
authored
Sep 02, 2020
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modifies job finder
parent
09b2c17a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
10 deletions
+48
-10
app/finders/ci/jobs_finder.rb
app/finders/ci/jobs_finder.rb
+38
-10
spec/finders/ci/jobs_finder_spec.rb
spec/finders/ci/jobs_finder_spec.rb
+10
-0
No files found.
app/finders/ci/jobs_finder.rb
View file @
3e4624f6
...
@@ -4,37 +4,54 @@ module Ci
...
@@ -4,37 +4,54 @@ module Ci
class
JobsFinder
class
JobsFinder
include
Gitlab
::
Allowable
include
Gitlab
::
Allowable
def
initialize
(
current_user
:,
project:
nil
,
params:
{})
def
initialize
(
current_user
:,
pipeline:
nil
,
project:
nil
,
params:
{},
type:
::
Ci
::
Build
)
@pipeline
=
pipeline
@current_user
=
current_user
@current_user
=
current_user
@project
=
project
@project
=
project
@params
=
params
@params
=
params
@type
=
type
raise
ArgumentError
'type must be a subclass of Ci::Processable'
unless
type
<
::
Ci
::
Processable
end
end
def
execute
def
execute
builds
=
init_collection
.
order_id_desc
builds
=
init_collection
.
order_id_desc
filter_by_scope
(
builds
)
if
params
[
:scope
].
is_a?
(
Array
)
unknown
=
params
[
:scope
]
-
::
CommitStatus
::
AVAILABLE_STATUSES
raise
ArgumentError
,
'Scope contains invalid value(s)'
unless
unknown
.
empty?
builds
.
where
(
status:
params
[
:scope
])
else
filter_by_scope
(
builds
)
end
rescue
Gitlab
::
Access
::
AccessDeniedError
rescue
Gitlab
::
Access
::
AccessDeniedError
Ci
::
Build
.
none
type
.
none
end
end
private
#
private
attr_reader
:current_user
,
:p
roject
,
:params
attr_reader
:current_user
,
:p
ipeline
,
:project
,
:params
,
:type
def
init_collection
def
init_collection
p
roject
?
project_builds
:
all_build
s
p
ipeline_jobs
||
project_jobs
||
all_job
s
end
end
def
all_
build
s
def
all_
job
s
raise
Gitlab
::
Access
::
AccessDeniedError
unless
current_user
&
.
admin?
raise
Gitlab
::
Access
::
AccessDeniedError
unless
current_user
&
.
admin?
Ci
::
Build
.
all
type
.
all
end
end
def
project_builds
def
project_jobs
return
unless
project
raise
Gitlab
::
Access
::
AccessDeniedError
unless
can?
(
current_user
,
:read_build
,
project
)
raise
Gitlab
::
Access
::
AccessDeniedError
unless
can?
(
current_user
,
:read_build
,
project
)
project
.
builds
.
relevant
jobs_by_type
(
project
,
type
).
relevant
end
def
pipeline_jobs
return
unless
pipeline
raise
Gitlab
::
Access
::
AccessDeniedError
unless
can?
(
current_user
,
:read_build
,
pipeline
)
jobs_by_type
(
pipeline
,
type
).
latest
end
end
def
filter_by_scope
(
builds
)
def
filter_by_scope
(
builds
)
...
@@ -49,5 +66,16 @@ module Ci
...
@@ -49,5 +66,16 @@ module Ci
builds
builds
end
end
end
end
def
jobs_by_type
(
relation
,
type
)
case
type
.
name
when
::
Ci
::
Build
.
name
relation
.
builds
when
::
Ci
::
Bridge
.
name
relation
.
bridges
else
raise
ArgumentError
,
"finder does not support
#{
type
}
type"
end
end
end
end
end
end
spec/finders/ci/jobs_finder_spec.rb
View file @
3e4624f6
...
@@ -10,6 +10,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
...
@@ -10,6 +10,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
let_it_be
(
:job_1
)
{
create
(
:ci_build
)
}
let_it_be
(
:job_1
)
{
create
(
:ci_build
)
}
let_it_be
(
:job_2
)
{
create
(
:ci_build
,
:running
)
}
let_it_be
(
:job_2
)
{
create
(
:ci_build
,
:running
)
}
let_it_be
(
:job_3
)
{
create
(
:ci_build
,
:success
,
pipeline:
pipeline
)
}
let_it_be
(
:job_3
)
{
create
(
:ci_build
,
:success
,
pipeline:
pipeline
)
}
let_it_be
(
:bridge
)
{
create
(
:ci_bridge
,
pipeline:
pipeline
)
}
let
(
:params
)
{
{}
}
let
(
:params
)
{
{}
}
...
@@ -53,6 +54,15 @@ RSpec.describe Ci::JobsFinder, '#execute' do
...
@@ -53,6 +54,15 @@ RSpec.describe Ci::JobsFinder, '#execute' do
it
{
expect
(
subject
).
to
match_array
([
jobs
[
index
]])
}
it
{
expect
(
subject
).
to
match_array
([
jobs
[
index
]])
}
end
end
end
end
context
'scope is an array'
do
let
(
:jobs
)
{
[
job_1
,
job_2
,
job_3
]
}
let
(
:params
)
{{
scope:
[
'running'
]
}}
it
'filters by the job statuses in the scope'
do
expect
(
subject
).
to
match_array
([
job_2
])
end
end
end
end
context
'a project is present'
do
context
'a project is present'
do
...
...
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