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
bb8560df
Commit
bb8560df
authored
Feb 09, 2021
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to filter requirements by status on GraphQL
Allow to filter requirementsby passed or failed status on graphql.
parent
0576477b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
126 additions
and
0 deletions
+126
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+10
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+20
-0
ee/app/finders/requirements_management/requirements_finder.rb
...pp/finders/requirements_management/requirements_finder.rb
+7
-0
ee/app/graphql/resolvers/requirements_management/requirements_resolver.rb
...esolvers/requirements_management/requirements_resolver.rb
+4
-0
ee/app/models/requirements_management/requirement.rb
ee/app/models/requirements_management/requirement.rb
+16
-0
ee/changelogs/unreleased/issue_224614-allow_filter_requirements_by_status.yml
...ased/issue_224614-allow_filter_requirements_by_status.yml
+5
-0
ee/spec/finders/requirements_management/requirements_finder_spec.rb
...nders/requirements_management/requirements_finder_spec.rb
+13
-0
ee/spec/graphql/resolvers/requirements_management/requirements_resolver_spec.rb
...ers/requirements_management/requirements_resolver_spec.rb
+9
-0
ee/spec/models/requirements_management/requirement_spec.rb
ee/spec/models/requirements_management/requirement_spec.rb
+28
-0
ee/spec/requests/api/graphql/project/requirements_management/requirements_spec.rb
...phql/project/requirements_management/requirements_spec.rb
+14
-0
No files found.
doc/api/graphql/reference/gitlab_schema.graphql
View file @
bb8560df
...
...
@@ -19733,6 +19733,11 @@ type Project {
"""
iids
:
[
ID
!]
"""
The
state
of
latest
requirement
test
report
.
"""
lastTestReportState
:
TestReportState
"""
Search
query
for
requirement
title
.
"""
...
...
@@ -19793,6 +19798,11 @@ type Project {
"""
last
:
Int
"""
The
state
of
latest
requirement
test
report
.
"""
lastTestReportState
:
TestReportState
"""
Search
query
for
requirement
title
.
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
bb8560df
...
...
@@ -57430,6 +57430,16 @@
}
},
"defaultValue": null
},
{
"name": "lastTestReportState",
"description": "The state of latest requirement test report.",
"type": {
"kind": "ENUM",
"name": "TestReportState",
"ofType": null
},
"defaultValue": null
}
],
"type": {
...
...
@@ -57534,6 +57544,16 @@
},
"defaultValue": null
},
{
"name": "lastTestReportState",
"description": "The state of latest requirement test report.",
"type": {
"kind": "ENUM",
"name": "TestReportState",
"ofType": null
},
"defaultValue": null
},
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
ee/app/finders/requirements_management/requirements_finder.rb
View file @
bb8560df
...
...
@@ -22,6 +22,7 @@ module RequirementsManagement
items
=
by_iid
(
items
)
items
=
by_author
(
items
)
items
=
by_search
(
items
)
items
=
by_last_test_report_state
(
items
)
sort
(
items
)
end
...
...
@@ -58,6 +59,12 @@ module RequirementsManagement
items
.
with_author
(
authors
)
end
def
by_last_test_report_state
(
items
)
return
items
unless
params
[
:last_test_report_state
]
items
.
with_last_test_report_state
(
params
[
:last_test_report_state
])
end
def
get_authors
(
username_param
)
# Save a DB hit if the current_user is the only author, or there are none.
return
current_user
if
[
username_param
].
flatten
==
[
current_user
&
.
username
]
...
...
ee/app/graphql/resolvers/requirements_management/requirements_resolver.rb
View file @
bb8560df
...
...
@@ -16,6 +16,10 @@ module Resolvers
required:
false
,
description:
'List of IIDs of requirements, e.g., [1, 2].'
argument
:last_test_report_state
,
::
Types
::
RequirementsManagement
::
TestReportStateEnum
,
required:
false
,
description:
'The state of latest requirement test report.'
def
resolve_with_lookahead
(
**
args
)
# The project could have been loaded in batch by `BatchLoader`.
# At this point we need the `id` of the project to query for issues, so
...
...
ee/app/models/requirements_management/requirement.rb
View file @
bb8560df
...
...
@@ -37,6 +37,22 @@ module RequirementsManagement
scope
:with_author
,
->
(
user
)
{
where
(
author:
user
)
}
scope
:counts_by_state
,
->
{
group
(
:state
).
count
}
# Used to filter requirements by latest test report state
scope
:include_last_test_report_with_state
,
->
do
joins
(
"INNER JOIN LATERAL (
SELECT DISTINCT ON (requirement_id) requirement_id, state
FROM requirements_management_test_reports
WHERE requirement_id = requirements.id
ORDER BY requirement_id, created_at DESC LIMIT 1
) AS test_reports ON true"
)
end
scope
:with_last_test_report_state
,
->
(
state
)
do
include_last_test_report_with_state
.
where
(
test_reports:
{
state:
state
}
)
end
class
<<
self
# Searches for records with a matching title.
#
...
...
ee/changelogs/unreleased/issue_224614-allow_filter_requirements_by_status.yml
0 → 100644
View file @
bb8560df
---
title
:
Allow to filter requirements by latest requirement test report status on GraphQL
merge_request
:
53767
author
:
type
:
added
ee/spec/finders/requirements_management/requirements_finder_spec.rb
View file @
bb8560df
...
...
@@ -51,6 +51,19 @@ RSpec.describe RequirementsManagement::RequirementsFinder do
end
end
context
'when last_test_report_state is set'
do
let
(
:params
)
{
{
project_id:
project
.
id
,
last_test_report_state:
'passed'
}
}
it
'returns matched requirements'
do
create
(
:test_report
,
state: :passed
)
create
(
:test_report
,
requirement:
requirement1
,
state: :failed
)
create
(
:test_report
,
requirement:
requirement1
,
state: :passed
)
create
(
:test_report
,
requirement:
requirement3
,
state: :passed
)
is_expected
.
to
match_array
([
requirement1
,
requirement3
])
end
end
context
'when user can not read requirements in the project'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
{
project_id:
project
.
id
}
}
...
...
ee/spec/graphql/resolvers/requirements_management/requirements_resolver_spec.rb
View file @
bb8560df
...
...
@@ -42,6 +42,15 @@ RSpec.describe Resolvers::RequirementsManagement::RequirementsResolver do
expect
(
resolve_requirements
(
iids:
[
requirement1
.
iid
,
requirement3
.
iid
])).
to
contain_exactly
(
requirement1
,
requirement3
)
end
it
'filters by last test report state'
do
create
(
:test_report
,
state: :failed
)
create
(
:test_report
,
requirement:
requirement1
,
state: :passed
)
create
(
:test_report
,
requirement:
requirement1
,
state: :failed
)
create
(
:test_report
,
requirement:
requirement3
,
state: :failed
)
expect
(
resolve_requirements
(
last_test_report_state:
'failed'
)).
to
contain_exactly
(
requirement1
,
requirement3
)
end
describe
'sorting'
do
context
'when sorting by created_at'
do
it
'sorts requirements ascending'
do
...
...
ee/spec/models/requirements_management/requirement_spec.rb
View file @
bb8560df
...
...
@@ -76,6 +76,34 @@ RSpec.describe RequirementsManagement::Requirement do
it
{
is_expected
.
to
contain_exactly
(
requirement_one
)
}
end
end
describe
'.with_last_test_report_state'
do
let_it_be
(
:requirement1
)
{
create
(
:requirement
)
}
let_it_be
(
:requirement2
)
{
create
(
:requirement
)
}
let_it_be
(
:requirement3
)
{
create
(
:requirement
)
}
before
do
create
(
:test_report
,
requirement:
requirement1
,
state: :passed
)
create
(
:test_report
,
requirement:
requirement1
,
state: :failed
)
create
(
:test_report
,
requirement:
requirement2
,
state: :failed
)
create
(
:test_report
,
requirement:
requirement2
,
state: :passed
)
create
(
:test_report
,
requirement:
requirement3
,
state: :passed
)
end
subject
{
described_class
.
with_last_test_report_state
(
state
)
}
context
'for passed state'
do
let
(
:state
)
{
'passed'
}
it
{
is_expected
.
to
contain_exactly
(
requirement2
,
requirement3
)
}
end
context
'for failed state'
do
let
(
:state
)
{
'failed'
}
it
{
is_expected
.
to
contain_exactly
(
requirement1
)
}
end
end
end
describe
'#last_test_report_state'
do
...
...
ee/spec/requests/api/graphql/project/requirements_management/requirements_spec.rb
View file @
bb8560df
...
...
@@ -95,6 +95,10 @@ RSpec.describe 'getting a requirement list for a project' do
let_it_be
(
:requirement2
)
{
create
(
:requirement
,
project:
filter_project
,
author:
other_user
,
title:
'something about kubernetes'
)
}
before
do
create
(
:test_report
,
requirement:
requirement1
,
state: :failed
)
create
(
:test_report
,
requirement:
requirement1
,
state: :passed
)
create
(
:test_report
,
requirement:
requirement2
,
state: :failed
)
post_graphql
(
query
,
current_user:
current_user
)
end
...
...
@@ -156,6 +160,16 @@ RSpec.describe 'getting a requirement list for a project' do
match_single_result
(
requirement2
)
end
end
context
'when given lastTestReportState'
do
let
(
:params
)
{
'(lastTestReportState: PASSED)'
}
it
'returns filtered requirements'
do
expect
(
graphql_errors
).
to
be_nil
match_single_result
(
requirement1
)
end
end
end
describe
'sorting and pagination'
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