Skip to content
代码片段 群组 项目
提交 3f4b5799 编辑于 作者: Steve Abrams's avatar Steve Abrams
浏览文件

Merge branch '382074-project-jobs-resolver-filter-by-with-artifacts' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -10,6 +10,7 @@ query getJobArtifacts( ...@@ -10,6 +10,7 @@ query getJobArtifacts(
project(fullPath: $projectPath) { project(fullPath: $projectPath) {
id id
jobs( jobs(
withArtifacts: true
statuses: [SUCCESS, FAILED] statuses: [SUCCESS, FAILED]
first: $firstPageSize first: $firstPageSize
last: $lastPageSize last: $lastPageSize
......
...@@ -16,6 +16,7 @@ def initialize(current_user:, pipeline: nil, project: nil, runner: nil, params: ...@@ -16,6 +16,7 @@ def initialize(current_user:, pipeline: nil, project: nil, runner: nil, params:
def execute def execute
builds = init_collection.order_id_desc builds = init_collection.order_id_desc
builds = filter_by_with_artifacts(builds)
filter_by_scope(builds) filter_by_scope(builds)
rescue Gitlab::Access::AccessDeniedError rescue Gitlab::Access::AccessDeniedError
type.none type.none
...@@ -72,6 +73,14 @@ def filter_by_scope(builds) ...@@ -72,6 +73,14 @@ def filter_by_scope(builds)
end end
end end
def filter_by_with_artifacts(builds)
if params[:with_artifacts]
builds.with_erasable_artifacts
else
builds
end
end
def filter_by_statuses!(builds) def filter_by_statuses!(builds)
unknown_statuses = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES unknown_statuses = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES
raise ArgumentError, 'Scope contains invalid value(s)' unless unknown_statuses.empty? raise ArgumentError, 'Scope contains invalid value(s)' unless unknown_statuses.empty?
......
...@@ -14,10 +14,18 @@ class ProjectJobsResolver < BaseResolver ...@@ -14,10 +14,18 @@ class ProjectJobsResolver < BaseResolver
required: false, required: false,
description: 'Filter jobs by status.' description: 'Filter jobs by status.'
argument :with_artifacts, ::GraphQL::Types::Boolean,
required: false,
description: 'Filter by artifacts presence.'
alias_method :project, :object alias_method :project, :object
def resolve_with_lookahead(statuses: nil) def resolve_with_lookahead(statuses: nil, with_artifacts: nil)
jobs = ::Ci::JobsFinder.new(current_user: current_user, project: project, params: { scope: statuses }).execute jobs = ::Ci::JobsFinder.new(
current_user: current_user, project: project, params: {
scope: statuses, with_artifacts: with_artifacts
}
).execute
apply_lookahead(jobs) apply_lookahead(jobs)
end end
......
...@@ -17666,6 +17666,7 @@ four standard [pagination arguments](#connection-pagination-arguments): ...@@ -17666,6 +17666,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="projectjobsstatuses"></a>`statuses` | [`[CiJobStatus!]`](#cijobstatus) | Filter jobs by status. | | <a id="projectjobsstatuses"></a>`statuses` | [`[CiJobStatus!]`](#cijobstatus) | Filter jobs by status. |
| <a id="projectjobswithartifacts"></a>`withArtifacts` | [`Boolean`](#boolean) | Filter by artifacts presence. |
   
##### `Project.label` ##### `Project.label`
   
...@@ -99,6 +99,33 @@ ...@@ -99,6 +99,33 @@
end end
end end
context 'when artifacts are present for some jobs' do
let_it_be(:job_with_artifacts) { create(:ci_build, :success, pipeline: pipeline, name: 'test') }
let_it_be(:artifact) { create(:ci_job_artifact, job: job_with_artifacts) }
subject { described_class.new(current_user: user, project: project, params: params).execute }
before do
project.add_maintainer(user)
end
context 'when with_artifacts is true' do
let(:params) { { with_artifacts: true } }
it 'returns only jobs with artifacts' do
expect(subject).to match_array([job_with_artifacts])
end
end
context 'when with_artifacts is false' do
let(:params) { { with_artifacts: false } }
it 'returns all jobs' do
expect(subject).to match_array([successful_job, job_with_artifacts])
end
end
end
context 'when pipeline is present' do context 'when pipeline is present' do
before_all do before_all do
project.add_maintainer(user) project.add_maintainer(user)
......
...@@ -492,7 +492,7 @@ ...@@ -492,7 +492,7 @@
subject { described_class.fields['jobs'] } subject { described_class.fields['jobs'] }
it { is_expected.to have_graphql_type(Types::Ci::JobType.connection_type) } it { is_expected.to have_graphql_type(Types::Ci::JobType.connection_type) }
it { is_expected.to have_graphql_arguments(:statuses) } it { is_expected.to have_graphql_arguments(:statuses, :with_artifacts) }
end end
describe 'ci_template field' do describe 'ci_template field' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册