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, authorization_scopes, authorize, authorized?, #current_user, #id

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#admin_urlObject



121
122
123
# File 'app/graphql/types/ci/runner_type.rb', line 121

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

#edit_admin_urlObject



125
126
127
# File 'app/graphql/types/ci/runner_type.rb', line 125

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

#ephemeral_authentication_tokenObject



148
149
150
# File 'app/graphql/types/ci/runner_type.rb', line 148

def ephemeral_authentication_token
  runner.token if runner.registration_available?
end

#ephemeral_register_urlObject



129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/graphql/types/ci/runner_type.rb', line 129

def ephemeral_register_url
  return unless context[:current_user]&.can?(:read_ephemeral_token, runner) && runner.registration_available?

  case runner.runner_type
  when 'instance_type'
    Gitlab::Routing.url_helpers.register_admin_runner_url(runner)
  when 'group_type'
    Gitlab::Routing.url_helpers.register_group_runner_url(runner.groups[0], runner)
  when 'project_type'
    Gitlab::Routing.url_helpers.register_project_runner_url(runner.projects[0], runner)
  end
end

#job_execution_statusObject



165
166
167
168
169
170
171
172
173
# File 'app/graphql/types/ci/runner_type.rb', line 165

def job_execution_status
  BatchLoader::GraphQL.for(runner.id).batch(key: :running_builds_exist) do |runner_ids, loader|
    statuses = ::Ci::Runner.id_in(runner_ids).with_executing_builds.index_by(&:id)

    runner_ids.each do |runner_id|
      loader.call(runner_id, statuses[runner_id] ? :active : :idle)
    end
  end
end

#maintenance_note_html_resolverObject



117
118
119
# File 'app/graphql/types/ci/runner_type.rb', line 117

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

#project_countObject



152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/graphql/types/ci/runner_type.rb', line 152

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)
      .id_in(ids)
      .group(:id) # rubocop: disable CodeReuse/ActiveRecord
      .index_by(&:id)

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

#register_admin_urlObject



142
143
144
145
146
# File 'app/graphql/types/ci/runner_type.rb', line 142

def register_admin_url
  return unless can_admin_all_runners? && runner.registration_available?

  Gitlab::Routing.url_helpers.register_admin_runner_url(runner)
end