2020-11-17 16:09:19 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
module Ci
|
|
|
|
class JobsResolver < BaseResolver
|
|
|
|
alias_method :pipeline, :object
|
|
|
|
|
2020-12-14 16:09:47 -05:00
|
|
|
type ::Types::Ci::JobType.connection_type, null: true
|
|
|
|
|
2020-11-17 16:09:19 -05:00
|
|
|
argument :security_report_types, [Types::Security::ReportTypeEnum],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'Filter jobs by the type of security report they produce.'
|
2020-11-17 16:09:19 -05:00
|
|
|
|
2021-03-23 05:09:17 -04:00
|
|
|
argument :statuses, [::Types::Ci::JobStatusEnum],
|
|
|
|
required: false,
|
|
|
|
description: 'Filter jobs by status.'
|
|
|
|
|
2022-07-13 11:09:14 -04:00
|
|
|
argument :retried, ::GraphQL::Types::Boolean,
|
|
|
|
required: false,
|
|
|
|
description: 'Filter jobs by retry-status.'
|
|
|
|
|
|
|
|
def resolve(statuses: nil, security_report_types: [], retried: nil)
|
2021-03-23 05:09:17 -04:00
|
|
|
jobs = init_collection(security_report_types)
|
|
|
|
jobs = jobs.with_status(statuses) if statuses.present?
|
2022-07-13 11:09:14 -04:00
|
|
|
jobs = jobs.retried if retried
|
|
|
|
jobs = jobs.latest if retried == false
|
2021-03-23 05:09:17 -04:00
|
|
|
|
|
|
|
jobs
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_collection(security_report_types)
|
2020-11-17 16:09:19 -05:00
|
|
|
if security_report_types.present?
|
|
|
|
::Security::SecurityJobsFinder.new(
|
|
|
|
pipeline: pipeline,
|
|
|
|
job_types: security_report_types
|
|
|
|
).execute
|
|
|
|
else
|
2021-12-14 07:13:33 -05:00
|
|
|
pipeline.statuses_order_id_desc
|
2020-11-17 16:09:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|