Commit d4fcc206 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'ci-processables' into 'master'

Introduce `Ci::Processable` as an abstract class

See merge request gitlab-org/gitlab!21821
parents 2d717f74 a1b3a232
# frozen_string_literal: true
module Ci
class Bridge < CommitStatus
include Ci::Processable
class Bridge < Ci::Processable
include Ci::Contextable
include Ci::PipelineDelegator
include Importable
......
# frozen_string_literal: true
module Ci
class Build < CommitStatus
include Ci::Processable
class Build < Ci::Processable
include Ci::Metadatable
include Ci::Contextable
include Ci::PipelineDelegator
......
......@@ -33,8 +33,7 @@ module Ci
has_many :stages, -> { order(position: :asc) }, inverse_of: :pipeline
has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id, inverse_of: :pipeline
has_many :latest_statuses_ordered_by_stage, -> { latest.order(:stage_idx, :stage) }, class_name: 'CommitStatus', foreign_key: :commit_id, inverse_of: :pipeline
has_many :processables, -> { processables },
class_name: 'CommitStatus', foreign_key: :commit_id, inverse_of: :pipeline
has_many :processables, class_name: 'Ci::Processable', foreign_key: :commit_id, inverse_of: :pipeline
has_many :builds, foreign_key: :commit_id, inverse_of: :pipeline
has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id # rubocop:disable Cop/ActiveRecordDependent
has_many :variables, class_name: 'Ci::PipelineVariable'
......
# frozen_string_literal: true
module Ci
##
# This module implements methods that need to be implemented by CI/CD
# entities that are supposed to go through pipeline processing
# services.
#
#
module Processable
extend ActiveSupport::Concern
class Processable < ::CommitStatus
has_many :needs, class_name: 'Ci::BuildNeed', foreign_key: :build_id, inverse_of: :build
included do
has_many :needs, class_name: 'Ci::BuildNeed', foreign_key: :build_id, inverse_of: :build
accepts_nested_attributes_for :needs
accepts_nested_attributes_for :needs
scope :preload_needs, -> { preload(:needs) }
scope :preload_needs, -> { preload(:needs) }
end
validates :type, presence: true
def schedulable?
raise NotImplementedError
......
......@@ -45,7 +45,6 @@ class CommitStatus < ApplicationRecord
scope :before_stage, -> (index) { where('stage_idx < ?', index) }
scope :for_stage, -> (index) { where(stage_idx: index) }
scope :after_stage, -> (index) { where('stage_idx > ?', index) }
scope :processables, -> { where(type: %w[Ci::Build Ci::Bridge]) }
scope :for_ids, -> (ids) { where(id: ids) }
scope :for_ref, -> (ref) { where(ref: ref) }
scope :by_name, -> (name) { where(name: name) }
......
# frozen_string_literal: true
module Ci
class BridgePresenter < CommitStatusPresenter
class BridgePresenter < ProcessablePresenter
def detailed_status
@detailed_status ||= subject.detailed_status(user)
end
......
# frozen_string_literal: true
module Ci
class BuildPresenter < CommitStatusPresenter
class BuildPresenter < ProcessablePresenter
def erased_by_user?
# Build can be erased through API, therefore it does not have
# `erased_by` user assigned in that case.
......
# frozen_string_literal: true
module Ci
class ProcessablePresenter < CommitStatusPresenter
end
end
......@@ -133,6 +133,7 @@ describe 'Database schema' do
'Ci::BuildTraceChunk' => %w[data_store],
'Ci::JobArtifact' => %w[file_type],
'Ci::Pipeline' => %w[source config_source failure_reason],
'Ci::Processable' => %w[failure_reason],
'Ci::Runner' => %w[access_level],
'Ci::Stage' => %w[status],
'Clusters::Applications::Ingress' => %w[ingress_type],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment