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
4dac350f
Commit
4dac350f
authored
Mar 02, 2022
by
charlie ablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose filter by `updated_before`/`updated_after` in GraphQL
parent
6fb28081
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
1 deletion
+70
-1
app/graphql/resolvers/concerns/resolves_pipelines.rb
app/graphql/resolvers/concerns/resolves_pipelines.rb
+8
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+6
-0
spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
+23
-1
spec/requests/api/graphql/ci/pipelines_spec.rb
spec/requests/api/graphql/ci/pipelines_spec.rb
+33
-0
No files found.
app/graphql/resolvers/concerns/resolves_pipelines.rb
View file @
4dac350f
...
@@ -24,6 +24,14 @@ module ResolvesPipelines
...
@@ -24,6 +24,14 @@ module ResolvesPipelines
GraphQL
::
Types
::
String
,
GraphQL
::
Types
::
String
,
required:
false
,
required:
false
,
description:
"Filter pipelines by their source."
description:
"Filter pipelines by their source."
argument
:updated_after
,
Types
::
TimeType
,
required:
false
,
description:
'Pipelines updated after this date.'
argument
:updated_before
,
Types
::
TimeType
,
required:
false
,
description:
'Pipelines updated before this date.'
argument
:username
,
argument
:username
,
GraphQL
::
Types
::
String
,
GraphQL
::
Types
::
String
,
required:
false
,
required:
false
,
...
...
doc/api/graphql/reference/index.md
View file @
4dac350f
...
@@ -9521,6 +9521,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
...
@@ -9521,6 +9521,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="commitpipelinessha"></a>`sha` | [`String`](#string) | Filter pipelines by the sha of the commit they are run for. |
| <a id="commitpipelinessha"></a>`sha` | [`String`](#string) | Filter pipelines by the sha of the commit they are run for. |
| <a id="commitpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <a id="commitpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <a id="commitpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
| <a id="commitpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
| <a id="commitpipelinesupdatedafter"></a>`updatedAfter` | [`Time`](#time) | Pipelines updated after this date. |
| <a id="commitpipelinesupdatedbefore"></a>`updatedBefore` | [`Time`](#time) | Pipelines updated before this date. |
| <a id="commitpipelinesusername"></a>`username` | [`String`](#string) | Filter pipelines by the user that triggered the pipeline. |
| <a id="commitpipelinesusername"></a>`username` | [`String`](#string) | Filter pipelines by the user that triggered the pipeline. |
### `ComplianceFramework`
### `ComplianceFramework`
...
@@ -12416,6 +12418,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
...
@@ -12416,6 +12418,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="mergerequestpipelinessha"></a>`sha` | [`String`](#string) | Filter pipelines by the sha of the commit they are run for. |
| <a id="mergerequestpipelinessha"></a>`sha` | [`String`](#string) | Filter pipelines by the sha of the commit they are run for. |
| <a id="mergerequestpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <a id="mergerequestpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <a id="mergerequestpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
| <a id="mergerequestpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
| <a id="mergerequestpipelinesupdatedafter"></a>`updatedAfter` | [`Time`](#time) | Pipelines updated after this date. |
| <a id="mergerequestpipelinesupdatedbefore"></a>`updatedBefore` | [`Time`](#time) | Pipelines updated before this date. |
| <a id="mergerequestpipelinesusername"></a>`username` | [`String`](#string) | Filter pipelines by the user that triggered the pipeline. |
| <a id="mergerequestpipelinesusername"></a>`username` | [`String`](#string) | Filter pipelines by the user that triggered the pipeline. |
##### `MergeRequest.reference`
##### `MergeRequest.reference`
...
@@ -14464,6 +14468,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
...
@@ -14464,6 +14468,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="projectpipelinessha"></a>`sha` | [`String`](#string) | Filter pipelines by the sha of the commit they are run for. |
| <a id="projectpipelinessha"></a>`sha` | [`String`](#string) | Filter pipelines by the sha of the commit they are run for. |
| <a id="projectpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <a id="projectpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <a id="projectpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
| <a id="projectpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
| <a id="projectpipelinesupdatedafter"></a>`updatedAfter` | [`Time`](#time) | Pipelines updated after this date. |
| <a id="projectpipelinesupdatedbefore"></a>`updatedBefore` | [`Time`](#time) | Pipelines updated before this date. |
| <a id="projectpipelinesusername"></a>`username` | [`String`](#string) | Filter pipelines by the user that triggered the pipeline. |
| <a id="projectpipelinesusername"></a>`username` | [`String`](#string) | Filter pipelines by the user that triggered the pipeline. |
##### `Project.projectMembers`
##### `Project.projectMembers`
spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
View file @
4dac350f
...
@@ -39,7 +39,7 @@ RSpec.describe ResolvesPipelines do
...
@@ -39,7 +39,7 @@ RSpec.describe ResolvesPipelines do
project
.
add_developer
(
current_user
)
project
.
add_developer
(
current_user
)
end
end
it
{
is_expected
.
to
have_graphql_arguments
(
:status
,
:scope
,
:ref
,
:sha
,
:source
,
:username
)
}
it
{
is_expected
.
to
have_graphql_arguments
(
:status
,
:scope
,
:ref
,
:sha
,
:source
,
:u
pdated_after
,
:updated_before
,
:u
sername
)
}
it
'finds all pipelines'
do
it
'finds all pipelines'
do
expect
(
resolve_pipelines
).
to
contain_exactly
(
*
all_pipelines
)
expect
(
resolve_pipelines
).
to
contain_exactly
(
*
all_pipelines
)
...
@@ -77,6 +77,28 @@ RSpec.describe ResolvesPipelines do
...
@@ -77,6 +77,28 @@ RSpec.describe ResolvesPipelines do
expect
(
resolve_pipelines
(
username:
current_user
.
username
)).
to
contain_exactly
(
username_pipeline
)
expect
(
resolve_pipelines
(
username:
current_user
.
username
)).
to
contain_exactly
(
username_pipeline
)
end
end
context
'filtering by updated_at'
do
let_it_be
(
:old_pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
updated_at:
2
.
days
.
ago
)
}
let_it_be
(
:older_pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
updated_at:
5
.
days
.
ago
)
}
it
'filters by updated_after'
do
expect
(
resolve_pipelines
(
updated_after:
3
.
days
.
ago
)).
to
contain_exactly
(
old_pipeline
,
*
all_pipelines
)
end
it
'filters by updated_before'
do
expect
(
resolve_pipelines
(
updated_before:
3
.
days
.
ago
)).
to
contain_exactly
(
older_pipeline
)
end
it
'filters by both updated_after and updated_before with valid date range'
do
expect
(
resolve_pipelines
(
updated_after:
10
.
days
.
ago
,
updated_before:
3
.
days
.
ago
)).
to
contain_exactly
(
older_pipeline
)
end
it
'filters by both updated_after and updated_before with invalid date range'
do
# updated_after is before updated_before so result set is empty - impossible
expect
(
resolve_pipelines
(
updated_after:
3
.
days
.
ago
,
updated_before:
10
.
days
.
ago
)).
to
be_empty
end
end
it
'does not return any pipelines if the user does not have access'
do
it
'does not return any pipelines if the user does not have access'
do
expect
(
resolve_pipelines
({},
{})).
to
be_empty
expect
(
resolve_pipelines
({},
{})).
to
be_empty
end
end
...
...
spec/requests/api/graphql/ci/pipelines_spec.rb
View file @
4dac350f
...
@@ -528,4 +528,37 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
...
@@ -528,4 +528,37 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
end
.
not_to
exceed_query_limit
(
control_count
)
end
.
not_to
exceed_query_limit
(
control_count
)
end
end
end
end
describe
'filtering'
do
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipelines(updatedAfter: "#{updated_after_arg}", updatedBefore: "#{updated_before_arg}") {
nodes {
id
}}}}
)
end
context
'when filtered by updated_at'
do
let_it_be
(
:oldish_pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
,
updated_at:
3
.
days
.
ago
)
}
let_it_be
(
:older_pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
,
updated_at:
10
.
days
.
ago
)
}
let
(
:updated_after_arg
)
{
5
.
days
.
ago
}
let
(
:updated_before_arg
)
{
1
.
day
.
ago
}
before
do
post_graphql
(
query
,
current_user:
user
)
end
it_behaves_like
'a working graphql query'
it
'accepts filter params'
do
pipeline_ids
=
graphql_data
.
dig
(
'project'
,
'pipelines'
,
'nodes'
).
map
{
|
pipeline
|
pipeline
.
fetch
(
'id'
)
}
expect
(
pipeline_ids
).
to
match_array
(
oldish_pipeline
.
to_global_id
.
to_s
)
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