diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /lib/gitlab/ci/pipeline/quota/deployments.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/gitlab/ci/pipeline/quota/deployments.rb')
-rw-r--r-- | lib/gitlab/ci/pipeline/quota/deployments.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/ci/pipeline/quota/deployments.rb b/lib/gitlab/ci/pipeline/quota/deployments.rb new file mode 100644 index 00000000000..ed32d0d3d49 --- /dev/null +++ b/lib/gitlab/ci/pipeline/quota/deployments.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Pipeline + module Quota + class Deployments < ::Gitlab::Ci::Limit + include ::Gitlab::Utils::StrongMemoize + include ActionView::Helpers::TextHelper + + def initialize(namespace, pipeline, command) + @namespace = namespace + @pipeline = pipeline + @command = command + end + + def enabled? + limit > 0 + end + + def exceeded? + return false unless enabled? + + pipeline_deployment_count > limit + end + + def message + return unless exceeded? + + "Pipeline has too many deployments! Requested #{pipeline_deployment_count}, but the limit is #{limit}." + end + + private + + def pipeline_deployment_count + strong_memoize(:pipeline_deployment_count) do + @command.pipeline_seed.deployments_count + end + end + + def limit + strong_memoize(:limit) do + @namespace.actual_limits.ci_pipeline_deployments + end + end + end + end + end + end +end |