Class: Types::Ci::PipelineType

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

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

#commitObject



213
214
215
# File 'app/graphql/types/ci/pipeline_type.rb', line 213

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

#commit_pathObject



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

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

#detailed_statusObject



228
229
230
# File 'app/graphql/types/ci/pipeline_type.rb', line 228

def detailed_status
  object.detailed_status(current_user)
end

#error_messagesObject



217
218
219
220
221
222
223
224
225
226
# File 'app/graphql/types/ci/pipeline_type.rb', line 217

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

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



256
257
258
259
260
261
262
263
264
# File 'app/graphql/types/ci/pipeline_type.rb', line 256

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

#pathObject



240
241
242
# File 'app/graphql/types/ci/pipeline_type.rb', line 240

def path
  ::Gitlab::Routing.url_helpers.project_pipeline_path(object.project, object)
end

#sha(format: ) ⇒ Object



266
267
268
269
270
# File 'app/graphql/types/ci/pipeline_type.rb', line 266

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

  pipeline.sha
end

#userObject



232
233
234
# File 'app/graphql/types/ci/pipeline_type.rb', line 232

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

#warning_messagesObject



244
245
246
247
248
249
250
251
252
253
254
# File 'app/graphql/types/ci/pipeline_type.rb', line 244

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