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 # frozen_string_literal: true
module Ci module Ci
class Bridge < CommitStatus class Bridge < Ci::Processable
include Ci::Processable
include Ci::Contextable include Ci::Contextable
include Ci::PipelineDelegator include Ci::PipelineDelegator
include Importable include Importable
......
# frozen_string_literal: true # frozen_string_literal: true
module Ci module Ci
class Build < CommitStatus class Build < Ci::Processable
include Ci::Processable
include Ci::Metadatable include Ci::Metadatable
include Ci::Contextable include Ci::Contextable
include Ci::PipelineDelegator include Ci::PipelineDelegator
......
...@@ -33,8 +33,7 @@ module Ci ...@@ -33,8 +33,7 @@ module Ci
has_many :stages, -> { order(position: :asc) }, inverse_of: :pipeline has_many :stages, -> { order(position: :asc) }, inverse_of: :pipeline
has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id, 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 :latest_statuses_ordered_by_stage, -> { latest.order(:stage_idx, :stage) }, class_name: 'CommitStatus', foreign_key: :commit_id, inverse_of: :pipeline
has_many :processables, -> { processables }, has_many :processables, class_name: 'Ci::Processable', foreign_key: :commit_id, inverse_of: :pipeline
class_name: 'CommitStatus', foreign_key: :commit_id, inverse_of: :pipeline
has_many :builds, 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 :trigger_requests, dependent: :destroy, foreign_key: :commit_id # rubocop:disable Cop/ActiveRecordDependent
has_many :variables, class_name: 'Ci::PipelineVariable' has_many :variables, class_name: 'Ci::PipelineVariable'
......
# frozen_string_literal: true # frozen_string_literal: true
module Ci module Ci
## class Processable < ::CommitStatus
# 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
included do
has_many :needs, class_name: 'Ci::BuildNeed', foreign_key: :build_id, inverse_of: :build 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? def schedulable?
raise NotImplementedError raise NotImplementedError
......
...@@ -45,7 +45,6 @@ class CommitStatus < ApplicationRecord ...@@ -45,7 +45,6 @@ class CommitStatus < ApplicationRecord
scope :before_stage, -> (index) { where('stage_idx < ?', index) } scope :before_stage, -> (index) { where('stage_idx < ?', index) }
scope :for_stage, -> (index) { where(stage_idx: index) } scope :for_stage, -> (index) { where(stage_idx: index) }
scope :after_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_ids, -> (ids) { where(id: ids) }
scope :for_ref, -> (ref) { where(ref: ref) } scope :for_ref, -> (ref) { where(ref: ref) }
scope :by_name, -> (name) { where(name: name) } scope :by_name, -> (name) { where(name: name) }
......
# frozen_string_literal: true # frozen_string_literal: true
module Ci module Ci
class BridgePresenter < CommitStatusPresenter class BridgePresenter < ProcessablePresenter
def detailed_status def detailed_status
@detailed_status ||= subject.detailed_status(user) @detailed_status ||= subject.detailed_status(user)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module Ci module Ci
class BuildPresenter < CommitStatusPresenter class BuildPresenter < ProcessablePresenter
def erased_by_user? def erased_by_user?
# Build can be erased through API, therefore it does not have # Build can be erased through API, therefore it does not have
# `erased_by` user assigned in that case. # `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 ...@@ -133,6 +133,7 @@ describe 'Database schema' do
'Ci::BuildTraceChunk' => %w[data_store], 'Ci::BuildTraceChunk' => %w[data_store],
'Ci::JobArtifact' => %w[file_type], 'Ci::JobArtifact' => %w[file_type],
'Ci::Pipeline' => %w[source config_source failure_reason], 'Ci::Pipeline' => %w[source config_source failure_reason],
'Ci::Processable' => %w[failure_reason],
'Ci::Runner' => %w[access_level], 'Ci::Runner' => %w[access_level],
'Ci::Stage' => %w[status], 'Ci::Stage' => %w[status],
'Clusters::Applications::Ingress' => %w[ingress_type], '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