diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-17 12:08:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-17 12:08:52 +0300 |
commit | 53ae6b7e3f83591ad251a3f771f5bf3b8cf087ba (patch) | |
tree | 5180b96d6a84f36a515cedfa8e81d72de5ccf4fb /app/models | |
parent | cfe63cce6a90a1c70397c1b9f6d90480f25cae0a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/commit_status_enums.rb | 1 | ||||
-rw-r--r-- | app/models/deployment.rb | 11 | ||||
-rw-r--r-- | app/models/environment.rb | 1 | ||||
-rw-r--r-- | app/models/member.rb | 1 | ||||
-rw-r--r-- | app/models/project.rb | 1 | ||||
-rw-r--r-- | app/models/project_ci_cd_setting.rb | 6 |
6 files changed, 21 insertions, 0 deletions
diff --git a/app/models/commit_status_enums.rb b/app/models/commit_status_enums.rb index dcf23d112d6..caebff91022 100644 --- a/app/models/commit_status_enums.rb +++ b/app/models/commit_status_enums.rb @@ -18,6 +18,7 @@ module CommitStatusEnums unmet_prerequisites: 10, scheduler_failure: 11, data_integrity_failure: 12, + forward_deployment_failure: 13, insufficient_bridge_permissions: 1_001, downstream_bridge_project_not_found: 1_002, invalid_bridge_trigger: 1_003, diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 68f50b13a07..fe42fb93633 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -41,6 +41,9 @@ class Deployment < ApplicationRecord scope :visible, -> { where(status: %i[running success failed canceled]) } scope :stoppable, -> { where.not(on_stop: nil).where.not(deployable_id: nil).success } + scope :active, -> { where(status: %i[created running]) } + scope :older_than, -> (deployment) { where('id < ?', deployment.id) } + scope :with_deployable, -> { includes(:deployable).where('deployable_id IS NOT NULL') } state_machine :status, initial: :created do event :run do @@ -74,6 +77,14 @@ class Deployment < ApplicationRecord Deployments::FinishedWorker.perform_async(id) end end + + after_transition any => :running do |deployment| + next unless deployment.project.forward_deployment_enabled? + + deployment.run_after_commit do + Deployments::ForwardDeploymentWorker.perform_async(id) + end + end end enum status: { diff --git a/app/models/environment.rb b/app/models/environment.rb index 4635b05fcc7..bb41c4a066e 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -12,6 +12,7 @@ class Environment < ApplicationRecord has_many :deployments, -> { visible }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :successful_deployments, -> { success }, class_name: 'Deployment' + has_many :active_deployments, -> { active }, class_name: 'Deployment' has_many :prometheus_alerts, inverse_of: :environment has_one :last_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment' diff --git a/app/models/member.rb b/app/models/member.rb index 57924161b63..a26a0615a6e 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -75,6 +75,7 @@ class Member < ApplicationRecord scope :reporters, -> { active.where(access_level: REPORTER) } scope :developers, -> { active.where(access_level: DEVELOPER) } scope :maintainers, -> { active.where(access_level: MAINTAINER) } + scope :non_guests, -> { where('members.access_level > ?', GUEST) } scope :masters, -> { maintainers } # @deprecated scope :owners, -> { active.where(access_level: OWNER) } scope :owners_and_maintainers, -> { active.where(access_level: [OWNER, MAINTAINER]) } diff --git a/app/models/project.rb b/app/models/project.rb index 1e27ce9f344..e16bd568153 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -343,6 +343,7 @@ class Project < ApplicationRecord delegate :last_pipeline, to: :commit, allow_nil: true delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: true delegate :default_git_depth, :default_git_depth=, to: :ci_cd_settings, prefix: :ci + delegate :forward_deployment_enabled, :forward_deployment_enabled=, :forward_deployment_enabled?, to: :ci_cd_settings # Validations validates :creator, presence: true, on: :create diff --git a/app/models/project_ci_cd_setting.rb b/app/models/project_ci_cd_setting.rb index a495d34c07c..b26a3025b61 100644 --- a/app/models/project_ci_cd_setting.rb +++ b/app/models/project_ci_cd_setting.rb @@ -18,6 +18,8 @@ class ProjectCiCdSetting < ApplicationRecord }, allow_nil: true + default_value_for :forward_deployment_enabled, true + def self.available? @available ||= ActiveRecord::Migrator.current_version >= MINIMUM_SCHEMA_VERSION @@ -28,6 +30,10 @@ class ProjectCiCdSetting < ApplicationRecord super end + def forward_deployment_enabled? + super && ::Feature.enabled?(:forward_deployment_enabled, project) + end + private def set_default_git_depth |