Class: Types::Ci::PipelineType

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObject

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

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Class Method Details

.authorization_scopesObject



15
16
17
# File 'app/graphql/types/ci/pipeline_type.rb', line 15

def self.authorization_scopes
  super + [:ai_workflows]
end

Instance Method Details

#commitObject



236
237
238
# File 'app/graphql/types/ci/pipeline_type.rb', line 236

def commit
  BatchLoader::GraphQL.wrap(object.commit)
end

#commit_pathObject



259
260
261
# File 'app/graphql/types/ci/pipeline_type.rb', line 259

def commit_path
  ::Gitlab::Routing.url_helpers.project_commit_path(object.project, object.sha)
end

#detailed_statusObject



251
252
253
# File 'app/graphql/types/ci/pipeline_type.rb', line 251

def detailed_status
  object.detailed_status(current_user)
end

#error_messagesObject



240
241
242
243
244
245
246
247
248
249
# File 'app/graphql/types/ci/pipeline_type.rb', line 240

def error_messages
  BatchLoader::GraphQL.for(object).batch do |pipelines, loader|
    # rubocop: disable CodeReuse/ActiveRecord -- no need to bloat the Pipeline model, we only need this functionality for GraphQL
    messages = ::Ci::PipelineMessage.where(pipeline: pipelines, severity: :error)
    # rubocop: enable CodeReuse/ActiveRecord
    pipelines.each do |pipeline|
      loader.call(pipeline, messages.select { |m| m.pipeline_id == pipeline.id })
    end
  end
end

#failed_jobs_countObject



299
300
301
302
303
304
305
# File 'app/graphql/types/ci/pipeline_type.rb', line 299

def failed_jobs_count
  BatchLoader::GraphQL.for(object).batch do |pipelines, loader|
    pipelines.each do |pipeline|
      loader.call(pipeline, pipeline.limited_failed_jobs.size)
    end
  end
end

#has_manual_actions?Boolean

Returns:

  • (Boolean)


291
292
293
# File 'app/graphql/types/ci/pipeline_type.rb', line 291

def has_manual_actions?
  object.association(:manual_actions).loaded? ? object.manual_actions.any? : object.manual_actions.exists?
end

#has_scheduled_actions?Boolean

Returns:

  • (Boolean)


295
296
297
# File 'app/graphql/types/ci/pipeline_type.rb', line 295

def has_scheduled_actions?
  object.association(:scheduled_actions).loaded? ? object.scheduled_actions.any? : object.scheduled_actions.exists?
end

#job(id: nil, name: nil) ⇒ Object



275
276
277
278
279
280
281
282
283
# File 'app/graphql/types/ci/pipeline_type.rb', line 275

def job(id: nil, name: nil)
  raise ::Gitlab::Graphql::Errors::ArgumentError, 'One of id or name is required' unless id || name

  if id
    pipeline.statuses.id_in(id.model_id)
  else
    pipeline.latest_statuses.by_name(name)
  end.take # rubocop: disable CodeReuse/ActiveRecord
end

#sha(format: ) ⇒ Object



285
286
287
288
289
# File 'app/graphql/types/ci/pipeline_type.rb', line 285

def sha(format: Types::ShaFormatEnum.enum[:long])
  return pipeline.short_sha if format == Types::ShaFormatEnum.enum[:short]

  pipeline.sha
end

#userObject



255
256
257
# File 'app/graphql/types/ci/pipeline_type.rb', line 255

def user
  Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.user_id).find
end

#warning_messagesObject



263
264
265
266
267
268
269
270
271
272
273
# File 'app/graphql/types/ci/pipeline_type.rb', line 263

def warning_messages
  BatchLoader::GraphQL.for(object).batch do |pipelines, loader|
    # rubocop: disable CodeReuse/ActiveRecord -- context specific
    messages = ::Ci::PipelineMessage.where(pipeline: pipelines, severity: :warning)
    # rubocop: enable CodeReuse/ActiveRecord

    pipelines.each do |pipeline|
      loader.call(pipeline, messages.select { |m| m.pipeline_id == pipeline.id })
    end
  end
end