Commit 4dac350f authored by charlie ablett's avatar charlie ablett

Expose filter by `updated_before`/`updated_after` in GraphQL

parent 6fb28081
......@@ -24,6 +24,14 @@ module ResolvesPipelines
GraphQL::Types::String,
required: false,
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,
GraphQL::Types::String,
required: false,
......
......@@ -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="commitpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <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. |
### `ComplianceFramework`
......@@ -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="mergerequestpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <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. |
##### `MergeRequest.reference`
......@@ -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="projectpipelinessource"></a>`source` | [`String`](#string) | Filter pipelines by their source. |
| <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. |
##### `Project.projectMembers`
......@@ -39,7 +39,7 @@ RSpec.describe ResolvesPipelines do
project.add_developer(current_user)
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, :updated_after, :updated_before, :username) }
it 'finds all pipelines' do
expect(resolve_pipelines).to contain_exactly(*all_pipelines)
......@@ -77,6 +77,28 @@ RSpec.describe ResolvesPipelines do
expect(resolve_pipelines(username: current_user.username)).to contain_exactly(username_pipeline)
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
expect(resolve_pipelines({}, {})).to be_empty
end
......
......@@ -528,4 +528,37 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
end.not_to exceed_query_limit(control_count)
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment