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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.4 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Resolvers
module Ci
class RunnersResolver < BaseResolver
2021-09-30 23:02:18 +05:30
include LooksAhead
2021-06-08 01:23:25 +05:30
type Types::Ci::RunnerType.connection_type, null: true
2022-01-26 12:08:38 +05:30
argument :active, ::GraphQL::Types::Boolean,
required: false,
2022-04-04 11:22:00 +05:30
description: 'Filter runners by `active` (true) or `paused` (false) status.',
deprecated: { reason: :renamed, replacement: 'paused', milestone: '14.8' }
argument :paused, ::GraphQL::Types::Boolean,
required: false,
description: 'Filter runners by `paused` (true) or `active` (false) status.'
2022-01-26 12:08:38 +05:30
2021-06-08 01:23:25 +05:30
argument :status, ::Types::Ci::RunnerStatusEnum,
required: false,
description: 'Filter runners by status.'
argument :type, ::Types::Ci::RunnerTypeEnum,
required: false,
description: 'Filter runners by type.'
2021-10-27 15:23:28 +05:30
argument :tag_list, [GraphQL::Types::String],
2021-06-08 01:23:25 +05:30
required: false,
description: 'Filter by tags associated with the runner (comma-separated or array).'
2021-10-27 15:23:28 +05:30
argument :search, GraphQL::Types::String,
2021-09-04 01:27:46 +05:30
required: false,
description: 'Filter by full token or partial text in description field.'
2021-06-08 01:23:25 +05:30
argument :sort, ::Types::Ci::RunnerSortEnum,
required: false,
description: 'Sort order of results.'
2021-09-30 23:02:18 +05:30
def resolve_with_lookahead(**args)
apply_lookahead(
::Ci::RunnersFinder
.new(current_user: current_user, params: runners_finder_params(args))
.execute)
2021-06-08 01:23:25 +05:30
end
2021-11-11 11:23:49 +05:30
protected
2021-06-08 01:23:25 +05:30
def runners_finder_params(params)
2022-04-04 11:22:00 +05:30
# Give preference to paused argument over the deprecated 'active' argument
paused = params.fetch(:paused, params[:active] ? !params[:active] : nil)
2021-06-08 01:23:25 +05:30
{
2022-04-04 11:22:00 +05:30
active: paused.nil? ? nil : !paused,
2021-06-08 01:23:25 +05:30
status_status: params[:status]&.to_s,
type_type: params[:type],
tag_name: params[:tag_list],
search: params[:search],
2021-09-30 23:02:18 +05:30
sort: params[:sort]&.to_s,
preload: {
tag_name: node_selection&.selects?(:tag_list)
}
2021-06-08 01:23:25 +05:30
}.compact
2021-11-11 11:23:49 +05:30
.merge(parent_param)
end
def parent_param
return {} unless parent
raise "Unexpected parent type: #{parent.class}"
end
private
def parent
object.respond_to?(:sync) ? object.sync : object
2021-06-08 01:23:25 +05:30
end
end
end
end