Class: Types::Ci::RunnerType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/types/ci/runner_type.rb

Constant Summary collapse

JOB_COUNT_LIMIT =
1000

Instance Method Summary collapse

Methods inherited from BaseObject

accepts, assignable?, authorization, authorize, authorized?, #current_user, #id

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#admin_urlObject


103
104
105
# File 'app/graphql/types/ci/runner_type.rb', line 103

def admin_url
  Gitlab::Routing.url_helpers.admin_runner_url(runner) if can_admin_runners?
end

#edit_admin_urlObject


107
108
109
# File 'app/graphql/types/ci/runner_type.rb', line 107

def edit_admin_url
  Gitlab::Routing.url_helpers.edit_admin_runner_url(runner) if can_admin_runners?
end

#groupsObject

rubocop: enable CodeReuse/ActiveRecord


128
129
130
131
132
# File 'app/graphql/types/ci/runner_type.rb', line 128

def groups
  return unless runner.group_type?

  batched_owners(::Ci::RunnerNamespace, Group, :runner_groups, :namespace_id)
end

#job_countObject


98
99
100
101
# File 'app/graphql/types/ci/runner_type.rb', line 98

def job_count
  # We limit to 1 above the JOB_COUNT_LIMIT to indicate that more items exist after JOB_COUNT_LIMIT
  runner.builds.limit(JOB_COUNT_LIMIT + 1).count
end

#maintenance_note_html_resolverObject


94
95
96
# File 'app/graphql/types/ci/runner_type.rb', line 94

def maintenance_note_html_resolver
  ::MarkupHelper.markdown(object.maintenance_note, context.to_h.dup)
end

#project_countObject

rubocop: disable CodeReuse/ActiveRecord


112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/graphql/types/ci/runner_type.rb', line 112

def project_count
  BatchLoader::GraphQL.for(runner.id).batch(key: :runner_project_count) do |ids, loader, args|
    counts = ::Ci::Runner.project_type
      .select(:id, 'COUNT(ci_runner_projects.id) as count')
      .left_outer_joins(:runner_projects)
      .where(id: ids)
      .group(:id)
      .index_by(&:id)

    ids.each do |id|
      loader.call(id, counts[id]&.count)
    end
  end
end

#projectsObject


134
135
136
137
138
# File 'app/graphql/types/ci/runner_type.rb', line 134

def projects
  return unless runner.project_type?

  batched_owners(::Ci::RunnerProject, Project, :runner_projects, :project_id)
end