debian-mirror-gitlab/app/models/ci/sources/pipeline.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
module Ci
module Sources
2021-10-27 15:23:28 +05:30
class Pipeline < Ci::ApplicationRecord
2023-03-04 22:38:38 +05:30
include Ci::Partitionable
2021-10-27 15:23:28 +05:30
include Ci::NamespacedModelName
2019-12-21 20:55:43 +05:30
self.table_name = "ci_sources_pipelines"
2022-07-23 23:45:48 +05:30
belongs_to :project, class_name: "::Project"
2019-12-21 20:55:43 +05:30
belongs_to :pipeline, class_name: "Ci::Pipeline", inverse_of: :source_pipeline
2023-05-27 22:25:52 +05:30
belongs_to :build, class_name: "Ci::Build", foreign_key: :source_job_id, inverse_of: :sourced_pipelines
2019-12-21 20:55:43 +05:30
2022-07-23 23:45:48 +05:30
belongs_to :source_project, class_name: "::Project", foreign_key: :source_project_id
2019-12-21 20:55:43 +05:30
belongs_to :source_job, class_name: "CommitStatus", foreign_key: :source_job_id
2020-03-13 15:44:24 +05:30
belongs_to :source_bridge, class_name: "Ci::Bridge", foreign_key: :source_job_id
2019-12-21 20:55:43 +05:30
belongs_to :source_pipeline, class_name: "Ci::Pipeline", foreign_key: :source_pipeline_id
2023-03-04 22:38:38 +05:30
partitionable scope: :pipeline
before_validation :set_source_partition_id, on: :create
validates :source_partition_id, presence: true
2019-12-21 20:55:43 +05:30
validates :project, presence: true
validates :pipeline, presence: true
validates :source_project, presence: true
validates :source_job, presence: true
validates :source_pipeline, presence: true
2020-03-13 15:44:24 +05:30
scope :same_project, -> { where(arel_table[:source_project_id].eq(arel_table[:project_id])) }
2023-03-04 22:38:38 +05:30
private
def set_source_partition_id
return if source_partition_id_changed? && source_partition_id.present?
return unless source_job
self.source_partition_id = source_job.partition_id
end
2019-12-21 20:55:43 +05:30
end
end
end