Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 21:09:27 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 21:09:27 +0300
commitbf213f07c8146b7121240af90a07cb4b2ecc41fa (patch)
tree184537ad2334124c5090f2a729a9fd58bccf6b51 /app/models
parentdd2da214c9644ef1064061d706dfeec50f9fad8f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/application_setting.rb2
-rw-r--r--app/models/ci/build.rb46
-rw-r--r--app/models/ci/runner.rb2
-rw-r--r--app/models/concerns/approvable_base.rb4
-rw-r--r--app/models/suggestion.rb20
5 files changed, 31 insertions, 43 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 4607f291a26..03d06117e83 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -9,7 +9,7 @@ class ApplicationSetting < ApplicationRecord
GRAFANA_URL_ERROR_MESSAGE = 'Please check your Grafana URL setting in ' \
'Admin Area > Settings > Metrics and profiling > Metrics - Grafana'
- add_authentication_token_field :runners_registration_token, encrypted: -> { Feature.enabled?(:application_settings_tokens_optional_encryption, default_enabled: true) ? :optional : :required }
+ add_authentication_token_field :runners_registration_token, encrypted: -> { Feature.enabled?(:application_settings_tokens_optional_encryption) ? :optional : :required }
add_authentication_token_field :health_check_access_token
add_authentication_token_field :static_objects_external_storage_auth_token
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 6c90645e997..733f28a2944 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -351,7 +351,7 @@ module Ci
after_transition any => [:failed] do |build|
next unless build.project
- if build.retry_failure?
+ if build.auto_retry_allowed?
begin
Ci::Build.retry(build, build.user)
rescue Gitlab::Access::AccessDeniedError => ex
@@ -373,6 +373,10 @@ module Ci
end
end
+ def auto_retry_allowed?
+ auto_retry.allowed?
+ end
+
def detailed_status(current_user)
Gitlab::Ci::Status::Build::Factory
.new(self, current_user)
@@ -439,27 +443,6 @@ module Ci
pipeline.builds.retried.where(name: self.name).count
end
- def retry_failure?
- max_allowed_retries = nil
- max_allowed_retries ||= options_retry_max if retry_on_reason_or_always?
- max_allowed_retries ||= DEFAULT_RETRIES.fetch(failure_reason.to_sym, 0)
-
- max_allowed_retries > 0 && retries_count < max_allowed_retries
- end
-
- def options_retry_max
- options_retry[:max]
- end
-
- def options_retry_when
- options_retry.fetch(:when, ['always'])
- end
-
- def retry_on_reason_or_always?
- options_retry_when.include?(failure_reason.to_s) ||
- options_retry_when.include?('always')
- end
-
def any_unmet_prerequisites?
prerequisites.present?
end
@@ -962,6 +945,12 @@ module Ci
private
+ def auto_retry
+ strong_memoize(:auto_retry) do
+ Gitlab::Ci::Build::AutoRetry.new(self)
+ end
+ end
+
def dependencies
strong_memoize(:dependencies) do
Ci::BuildDependencies.new(self)
@@ -1017,19 +1006,6 @@ module Ci
end
end
- # The format of the retry option changed in GitLab 11.5: Before it was
- # integer only, after it is a hash. New builds are created with the new
- # format, but builds created before GitLab 11.5 and saved in database still
- # have the old integer only format. This method returns the retry option
- # normalized as a hash in 11.5+ format.
- def options_retry
- strong_memoize(:options_retry) do
- value = options&.dig(:retry)
- value = value.is_a?(Integer) ? { max: value } : value.to_h
- value.with_indifferent_access
- end
- end
-
def has_expiring_artifacts?
artifacts_expire_at.present? && artifacts_expire_at > Time.current
end
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 1cd6c64841b..00ee45740bd 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -10,7 +10,7 @@ module Ci
include TokenAuthenticatable
include IgnorableColumns
- add_authentication_token_field :token, encrypted: -> { Feature.enabled?(:ci_runners_tokens_optional_encryption, default_enabled: true) ? :optional : :required }
+ add_authentication_token_field :token, encrypted: -> { Feature.enabled?(:ci_runners_tokens_optional_encryption) ? :optional : :required }
enum access_level: {
not_protected: 0,
diff --git a/app/models/concerns/approvable_base.rb b/app/models/concerns/approvable_base.rb
index 6323bd01c58..d07c4ec43ac 100644
--- a/app/models/concerns/approvable_base.rb
+++ b/app/models/concerns/approvable_base.rb
@@ -13,4 +13,8 @@ module ApprovableBase
approved_by_users.include?(user)
end
+
+ def can_be_approved_by?(user)
+ user && !approved_by?(user) && user.can?(:approve_merge_request, self)
+ end
end
diff --git a/app/models/suggestion.rb b/app/models/suggestion.rb
index 94f3a140098..c027a0d140e 100644
--- a/app/models/suggestion.rb
+++ b/app/models/suggestion.rb
@@ -43,12 +43,12 @@ class Suggestion < ApplicationRecord
def inapplicable_reason(cached: true)
strong_memoize("inapplicable_reason_#{cached}") do
- next :applied if applied?
- next :merge_request_merged if noteable.merged?
- next :merge_request_closed if noteable.closed?
- next :source_branch_deleted unless noteable.source_branch_exists?
- next :outdated if outdated?(cached: cached) || !note.active?
- next :same_content unless different_content?
+ next _("Can't apply this suggestion.") if applied?
+ next _("This merge request was merged. To apply this suggestion, edit this file directly.") if noteable.merged?
+ next _("This merge request is closed. To apply this suggestion, edit this file directly.") if noteable.closed?
+ next _("Can't apply as the source branch was deleted.") unless noteable.source_branch_exists?
+ next outdated_reason if outdated?(cached: cached) || !note.active?
+ next _("This suggestion already matches its content.") unless different_content?
end
end
@@ -73,4 +73,12 @@ class Suggestion < ApplicationRecord
def different_content?
from_content != to_content
end
+
+ def outdated_reason
+ if single_line?
+ _("Can't apply as this line was changed in a more recent version.")
+ else
+ _("Can't apply as these lines were changed in a more recent version.")
+ end
+ end
end