summaryrefslogtreecommitdiff
path: root/app/models/ci
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 18:09:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 18:09:21 +0000
commite0fa0638a422c3e20d4423c9bb69d79afc9c7d3d (patch)
tree9abb3c0706576bbda895fe9539a55556930606e2 /app/models/ci
parentf8d15ca65390475e356b06dedc51e10ccd179f86 (diff)
downloadgitlab-ce-e0fa0638a422c3e20d4423c9bb69d79afc9c7d3d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/pipeline.rb10
-rw-r--r--app/models/ci/ref.rb23
2 files changed, 32 insertions, 1 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 869a2e8da20..e07abc20dcf 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -63,6 +63,14 @@ module Ci
has_many :sourced_pipelines, class_name: 'Ci::Sources::Pipeline', foreign_key: :source_pipeline_id
has_one :source_pipeline, class_name: 'Ci::Sources::Pipeline', inverse_of: :pipeline
+
+ has_one :ref_status, ->(pipeline) {
+ # We use .read_attribute to save 1 extra unneeded query to load the :project.
+ unscope(:where)
+ .where(project_id: pipeline.read_attribute(:project_id), ref: pipeline.ref, tag: pipeline.tag)
+ # Sadly :inverse_of is not supported (yet) by Rails for composite PKs.
+ }, class_name: 'Ci::Ref', inverse_of: :pipelines
+
has_one :chat_data, class_name: 'Ci::PipelineChatData'
has_many :triggered_pipelines, through: :sourced_pipelines, source: :pipeline
@@ -227,7 +235,7 @@ module Ci
after_transition any => [:success, :failed] do |pipeline|
pipeline.run_after_commit do
- PipelineNotificationWorker.perform_async(pipeline.id)
+ PipelineUpdateCiRefStatusWorker.perform_async(pipeline.id)
end
end
diff --git a/app/models/ci/ref.rb b/app/models/ci/ref.rb
new file mode 100644
index 00000000000..a0782bc0444
--- /dev/null
+++ b/app/models/ci/ref.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Ci
+ class Ref < ApplicationRecord
+ extend Gitlab::Ci::Model
+
+ STATUSES = %w[success failed fixed].freeze
+
+ belongs_to :project
+ belongs_to :last_updated_by_pipeline, foreign_key: :last_updated_by_pipeline_id, class_name: 'Ci::Pipeline'
+ # ActiveRecord doesn't support composite FKs for this reason we have to do the 'unscope(:where)'
+ # hack.
+ has_many :pipelines, ->(ref) {
+ # We use .read_attribute to save 1 extra unneeded query to load the :project.
+ unscope(:where)
+ .where(ref: ref.ref, project_id: ref.read_attribute(:project_id), tag: ref.tag)
+ # Sadly :inverse_of is not supported (yet) by Rails for composite PKs.
+ }, inverse_of: :ref_status
+
+ validates :status, inclusion: { in: STATUSES }
+ validates :last_updated_by_pipeline, presence: true
+ end
+end