debian-mirror-gitlab/app/graphql/resolvers/ci/jobs_resolver.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Resolvers
module Ci
class JobsResolver < BaseResolver
alias_method :pipeline, :object
2021-02-22 17:27:13 +05:30
type ::Types::Ci::JobType.connection_type, null: true
2021-01-29 00:20:46 +05:30
argument :security_report_types, [Types::Security::ReportTypeEnum],
required: false,
2021-03-08 18:12:59 +05:30
description: 'Filter jobs by the type of security report they produce.'
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
argument :statuses, [::Types::Ci::JobStatusEnum],
required: false,
description: 'Filter jobs by status.'
2022-08-13 15:12:31 +05:30
argument :retried, ::GraphQL::Types::Boolean,
required: false,
description: 'Filter jobs by retry-status.'
2023-03-17 16:20:25 +05:30
argument :when_executed, [::GraphQL::Types::String],
required: false,
description: 'Filter jobs by when they are executed.'
def resolve(statuses: nil, security_report_types: [], retried: nil, when_executed: nil)
2021-04-29 21:17:54 +05:30
jobs = init_collection(security_report_types)
jobs = jobs.with_status(statuses) if statuses.present?
2022-08-13 15:12:31 +05:30
jobs = jobs.retried if retried
2023-03-17 16:20:25 +05:30
jobs = jobs.with_when_executed(when_executed) if when_executed.present?
2022-08-13 15:12:31 +05:30
jobs = jobs.latest if retried == false
2021-04-29 21:17:54 +05:30
jobs
end
def init_collection(security_report_types)
2021-01-29 00:20:46 +05:30
if security_report_types.present?
::Security::SecurityJobsFinder.new(
pipeline: pipeline,
job_types: security_report_types
).execute
else
2022-01-26 12:08:38 +05:30
pipeline.statuses_order_id_desc
2021-01-29 00:20:46 +05:30
end
end
end
end
end