Commit 85ebea6c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '341373-dast-view-scans-pipelines-statuses-filter' into 'master'

Add scope parameter to Project.pipelines query

See merge request gitlab-org/gitlab!74323
parents 9f84c717 b7b4f8d8
......@@ -5,6 +5,13 @@ module Ci
attr_reader :project, :pipelines, :params, :current_user
ALLOWED_INDEXED_COLUMNS = %w[id status ref updated_at user_id].freeze
ALLOWED_SCOPES = {
RUNNING: 'running',
PENDING: 'pending',
FINISHED: 'finished',
BRANCHES: 'branches',
TAGS: 'tags'
}.freeze
def initialize(project, current_user, params = {})
@project = project
......@@ -65,15 +72,15 @@ module Ci
def by_scope(items)
case params[:scope]
when 'running'
when ALLOWED_SCOPES[:RUNNING]
items.running
when 'pending'
when ALLOWED_SCOPES[:PENDING]
items.pending
when 'finished'
when ALLOWED_SCOPES[:FINISHED]
items.finished
when 'branches'
when ALLOWED_SCOPES[:BRANCHES]
from_ids(ids_for_ref(branches))
when 'tags'
when ALLOWED_SCOPES[:TAGS]
from_ids(ids_for_ref(tags))
else
items
......
......@@ -9,6 +9,9 @@ module ResolvesPipelines
Types::Ci::PipelineStatusEnum,
required: false,
description: "Filter pipelines by their status."
argument :scope, ::Types::Ci::PipelineScopeEnum,
required: false,
description: 'Filter pipelines by scope.'
argument :ref,
GraphQL::Types::String,
required: false,
......
# frozen_string_literal: true
module Types
module Ci
class PipelineScopeEnum < BaseEnum
SCOPES_DESCRIPTION = {
running: 'Pipeline is running.',
pending: 'Pipeline has not started running yet.',
finished: 'Pipeline has completed.',
branches: 'Branches.',
tags: 'Tags.'
}.freeze
SCOPES_DESCRIPTION.each do |scope, description|
value scope.to_s.upcase,
description: description,
value: scope.to_s
end
end
end
end
......@@ -3,10 +3,24 @@
module Types
module Ci
class PipelineStatusEnum < BaseEnum
::Ci::Pipeline.all_state_names.each do |state_symbol|
value state_symbol.to_s.upcase,
description: "#{::Ci::Pipeline::STATUSES_DESCRIPTION[state_symbol]}.",
value: state_symbol.to_s
STATUSES_DESCRIPTION = {
created: 'Pipeline has been created.',
waiting_for_resource: 'A resource (for example, a runner) that the pipeline requires to run is unavailable.',
preparing: 'Pipeline is preparing to run.',
pending: 'Pipeline has not started running yet.',
running: 'Pipeline is running.',
failed: 'At least one stage of the pipeline failed.',
success: 'Pipeline completed successfully.',
canceled: 'Pipeline was canceled before completion.',
skipped: 'Pipeline was skipped.',
manual: 'Pipeline needs to be manually started.',
scheduled: 'Pipeline is scheduled to run.'
}.freeze
STATUSES_DESCRIPTION.each do |state, description|
value state.to_s.upcase,
description: description,
value: state.to_s
end
end
end
......
......@@ -14,21 +14,8 @@ module Ci
PASSED_WITH_WARNINGS_STATUSES = %w[failed canceled].to_set.freeze
EXCLUDE_IGNORED_STATUSES = %w[manual failed canceled].to_set.freeze
STATUSES_ENUM = { created: 0, pending: 1, running: 2, success: 3,
failed: 4, canceled: 5, skipped: 6, manual: 7,
scheduled: 8, preparing: 9, waiting_for_resource: 10 }.freeze
STATUSES_DESCRIPTION = {
created: 'Pipeline has been created',
waiting_for_resource: 'A resource (for example, a runner) that the pipeline requires to run is unavailable',
preparing: 'Pipeline is preparing to run',
pending: 'Pipeline has not started running yet',
running: 'Pipeline is running',
failed: 'At least one stage of the pipeline failed',
success: 'Pipeline completed successfully',
canceled: 'Pipeline was canceled before completion',
skipped: 'Pipeline was skipped',
manual: 'Pipeline needs to be manually started',
scheduled: 'Pipeline is scheduled to run'
}.freeze
failed: 4, canceled: 5, skipped: 6, manual: 7,
scheduled: 8, preparing: 9, waiting_for_resource: 10 }.freeze
UnknownStatusError = Class.new(StandardError)
......
......@@ -8877,6 +8877,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="commitpipelinesref"></a>`ref` | [`String`](#string) | Filter pipelines by the ref they are run for. |
| <a id="commitpipelinesscope"></a>`scope` | [`PipelineScopeEnum`](#pipelinescopeenum) | Filter pipelines by scope. |
| <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. Will be ignored if `dast_view_scans` feature flag is disabled. |
| <a id="commitpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
......@@ -11605,6 +11606,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mergerequestpipelinesref"></a>`ref` | [`String`](#string) | Filter pipelines by the ref they are run for. |
| <a id="mergerequestpipelinesscope"></a>`scope` | [`PipelineScopeEnum`](#pipelinescopeenum) | Filter pipelines by scope. |
| <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. Will be ignored if `dast_view_scans` feature flag is disabled. |
| <a id="mergerequestpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
......@@ -13497,6 +13499,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="projectpipelinesref"></a>`ref` | [`String`](#string) | Filter pipelines by the ref they are run for. |
| <a id="projectpipelinesscope"></a>`scope` | [`PipelineScopeEnum`](#pipelinescopeenum) | Filter pipelines by scope. |
| <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. Will be ignored if `dast_view_scans` feature flag is disabled. |
| <a id="projectpipelinesstatus"></a>`status` | [`PipelineStatusEnum`](#pipelinestatusenum) | Filter pipelines by their status. |
......@@ -16701,6 +16704,16 @@ Values for sorting package.
| <a id="pipelineconfigsourceenumunknown_source"></a>`UNKNOWN_SOURCE` | Unknown source. |
| <a id="pipelineconfigsourceenumwebide_source"></a>`WEBIDE_SOURCE` | Webide source. |
### `PipelineScopeEnum`
| Value | Description |
| ----- | ----------- |
| <a id="pipelinescopeenumbranches"></a>`BRANCHES` | Branches. |
| <a id="pipelinescopeenumfinished"></a>`FINISHED` | Pipeline has completed. |
| <a id="pipelinescopeenumpending"></a>`PENDING` | Pipeline has not started running yet. |
| <a id="pipelinescopeenumrunning"></a>`RUNNING` | Pipeline is running. |
| <a id="pipelinescopeenumtags"></a>`TAGS` | Tags. |
### `PipelineStatusEnum`
| Value | Description |
......@@ -20,23 +20,37 @@ RSpec.describe ResolvesPipelines do
let_it_be(:project) { create(:project, :private) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:failed_pipeline) { create(:ci_pipeline, :failed, project: project) }
let_it_be(:success_pipeline) { create(:ci_pipeline, :success, project: project) }
let_it_be(:ref_pipeline) { create(:ci_pipeline, project: project, ref: 'awesome-feature') }
let_it_be(:sha_pipeline) { create(:ci_pipeline, project: project, sha: 'deadbeef') }
let_it_be(:all_pipelines) do
[
pipeline,
failed_pipeline,
success_pipeline,
ref_pipeline,
sha_pipeline
]
end
before do
project.add_developer(current_user)
end
it { is_expected.to have_graphql_arguments(:status, :ref, :sha, :source) }
it { is_expected.to have_graphql_arguments(:status, :scope, :ref, :sha, :source) }
it 'finds all pipelines' do
expect(resolve_pipelines).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline)
expect(resolve_pipelines).to contain_exactly(*all_pipelines)
end
it 'allows filtering by status' do
expect(resolve_pipelines(status: 'failed')).to contain_exactly(failed_pipeline)
end
it 'allows filtering by scope' do
expect(resolve_pipelines(scope: 'finished')).to contain_exactly(failed_pipeline, success_pipeline)
end
it 'allows filtering by ref' do
expect(resolve_pipelines(ref: 'awesome-feature')).to contain_exactly(ref_pipeline)
end
......@@ -54,7 +68,7 @@ RSpec.describe ResolvesPipelines do
end
it 'does not filter by source' do
expect(resolve_pipelines(source: 'web')).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline, source_pipeline)
expect(resolve_pipelines(source: 'web')).to contain_exactly(*all_pipelines, source_pipeline)
end
end
......@@ -64,7 +78,7 @@ RSpec.describe ResolvesPipelines do
end
it 'returns all the pipelines' do
expect(resolve_pipelines).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline, source_pipeline)
expect(resolve_pipelines).to contain_exactly(*all_pipelines, source_pipeline)
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::Ci::PipelineScopeEnum do
it 'exposes all pipeline scopes' do
expect(described_class.values.keys).to contain_exactly(
*::Ci::PipelinesFinder::ALLOWED_SCOPES.keys.map(&:to_s)
)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::Ci::PipelineStatusEnum do
it 'exposes all pipeline states' do
expect(described_class.values.keys).to contain_exactly(
*::Ci::Pipeline.all_state_names.map(&:to_s).map(&:upcase)
)
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