diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 15:08:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 15:08:49 +0300 |
commit | 1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (patch) | |
tree | 614a93d9bf8df34ecfc25c02648329987fb21dde /app/models | |
parent | f0707f413ce49b5712fca236b950acbec029be1e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/bridge.rb | 3 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 24 | ||||
-rw-r--r-- | app/models/concerns/ci/pipeline_delegator.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/has_ref.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/reactive_caching.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request/pipelines.rb | 2 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 18 |
8 files changed, 37 insertions, 18 deletions
diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb index bb22cc3e039..26997d17816 100644 --- a/app/models/ci/bridge.rb +++ b/app/models/ci/bridge.rb @@ -186,7 +186,8 @@ module Ci }, execute_params: { ignore_skip_ci: true, - bridge: self + bridge: self, + merge_request: parent_pipeline.merge_request } } end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index bb59fc937b1..a8685da3cd9 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -77,9 +77,7 @@ module Ci validates :sha, presence: { unless: :importing? } validates :ref, presence: { unless: :importing? } - validates :merge_request, presence: { if: :merge_request_event? } - validates :merge_request, absence: { unless: :merge_request_event? } - validates :tag, inclusion: { in: [false], if: :merge_request_event? } + validates :tag, inclusion: { in: [false], if: :merge_request? } validates :external_pull_request, presence: { if: :external_pull_request_event? } validates :external_pull_request, absence: { unless: :external_pull_request_event? } @@ -662,7 +660,7 @@ module Ci variables.concat(predefined_commit_variables) - if merge_request_event? && merge_request + if merge_request? variables.append(key: 'CI_MERGE_REQUEST_EVENT_TYPE', value: merge_request_event_type.to_s) variables.append(key: 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA', value: source_sha.to_s) variables.append(key: 'CI_MERGE_REQUEST_TARGET_BRANCH_SHA', value: target_sha.to_s) @@ -720,7 +718,7 @@ module Ci # All the merge requests for which the current pipeline runs/ran against def all_merge_requests @all_merge_requests ||= - if merge_request_event? + if merge_request? MergeRequest.where(id: merge_request_id) else MergeRequest.where(source_project_id: project_id, source_branch: ref) @@ -812,7 +810,7 @@ module Ci # * nil: Modified path can not be evaluated def modified_paths strong_memoize(:modified_paths) do - if merge_request_event? + if merge_request? merge_request.modified_paths elsif branch_updated? push_details.modified_paths @@ -836,12 +834,12 @@ module Ci ref == project.default_branch end - def triggered_by_merge_request? - merge_request_event? && merge_request_id.present? + def merge_request? + merge_request_id.present? end def detached_merge_request_pipeline? - triggered_by_merge_request? && target_sha.nil? + merge_request? && target_sha.nil? end def legacy_detached_merge_request_pipeline? @@ -849,7 +847,7 @@ module Ci end def merge_request_pipeline? - triggered_by_merge_request? && target_sha.present? + merge_request? && target_sha.present? end def merge_request_ref? @@ -865,7 +863,7 @@ module Ci end def source_ref - if triggered_by_merge_request? + if merge_request? merge_request.source_branch else ref @@ -885,7 +883,7 @@ module Ci end def merge_request_event_type - return unless merge_request_event? + return unless merge_request? strong_memoize(:merge_request_event_type) do if merge_request_pipeline? @@ -918,7 +916,7 @@ module Ci def git_ref strong_memoize(:git_ref) do - if merge_request_event? + if merge_request? ## # In the future, we're going to change this ref to # merge request's merged reference, such as "refs/merge-requests/:iid/merge". diff --git a/app/models/concerns/ci/pipeline_delegator.rb b/app/models/concerns/ci/pipeline_delegator.rb index 9f95dc38422..68ad0fcee31 100644 --- a/app/models/concerns/ci/pipeline_delegator.rb +++ b/app/models/concerns/ci/pipeline_delegator.rb @@ -11,7 +11,7 @@ module Ci extend ActiveSupport::Concern included do - delegate :merge_request_event?, + delegate :merge_request?, :merge_request_ref?, :legacy_detached_merge_request_pipeline?, :merge_train_pipeline?, to: :pipeline diff --git a/app/models/concerns/has_ref.rb b/app/models/concerns/has_ref.rb index fa0cf5ddfd2..22e5955984d 100644 --- a/app/models/concerns/has_ref.rb +++ b/app/models/concerns/has_ref.rb @@ -7,7 +7,7 @@ module HasRef extend ActiveSupport::Concern def branch? - !tag? && !merge_request_event? + !tag? && !merge_request? end def git_ref diff --git a/app/models/concerns/reactive_caching.rb b/app/models/concerns/reactive_caching.rb index 28d65e0bd45..010e0018414 100644 --- a/app/models/concerns/reactive_caching.rb +++ b/app/models/concerns/reactive_caching.rb @@ -9,6 +9,8 @@ module ReactiveCaching ExceededReactiveCacheLimit = Class.new(StandardError) included do + extend ActiveModel::Naming + class_attribute :reactive_cache_key class_attribute :reactive_cache_lease_timeout class_attribute :reactive_cache_refresh_interval diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index cf2763180c4..b8f51b58fd3 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1163,7 +1163,7 @@ class MergeRequest < ApplicationRecord # Since deployments run on a merge request ref (e.g. `refs/merge-requests/:iid/head`), # we cannot look up environments with source branch name. def environments - return Environment.none unless actual_head_pipeline&.triggered_by_merge_request? + return Environment.none unless actual_head_pipeline&.merge_request? actual_head_pipeline.environments end diff --git a/app/models/merge_request/pipelines.rb b/app/models/merge_request/pipelines.rb index c32f29a9304..72756e8e9d0 100644 --- a/app/models/merge_request/pipelines.rb +++ b/app/models/merge_request/pipelines.rb @@ -61,6 +61,8 @@ class MergeRequest::Pipelines pipelines.joins(shas_table) end + # NOTE: this method returns only parent merge request pipelines. + # Child merge request pipelines have a different source. def triggered_by_merge_request source_project.ci_pipelines .where(source: :merge_request_event, merge_request: merge_request) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index c6867e48cbf..26beb77a025 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -5,6 +5,9 @@ class WikiPage PageChangedError = Class.new(StandardError) PageRenameError = Class.new(StandardError) + MAX_TITLE_BYTES = 245 + MAX_DIRECTORY_BYTES = 255 + include ActiveModel::Validations include ActiveModel::Conversion include StaticModel @@ -51,6 +54,7 @@ class WikiPage validates :title, presence: true validates :content, presence: true + validate :validate_path_limits, if: :title_changed? # The GitLab ProjectWiki instance. attr_reader :wiki @@ -262,7 +266,7 @@ class WikiPage end def title_changed? - title.present? && self.class.unhyphenize(@page.url_path) != title + title.present? && (@page.nil? || self.class.unhyphenize(@page.url_path) != title) end # Updates the current @attributes hash by merging a hash of params @@ -324,4 +328,16 @@ class WikiPage set_attributes @persisted = errors.blank? end + + def validate_path_limits + *dirnames, title = @attributes[:title].split('/') + + if title.bytesize > MAX_TITLE_BYTES + errors.add(:title, _("exceeds the limit of %{bytes} bytes for page titles") % { bytes: MAX_TITLE_BYTES }) + end + + if dirnames.any? { |d| d.bytesize > MAX_DIRECTORY_BYTES } + errors.add(:title, _("exceeds the limit of %{bytes} bytes for directory names") % { bytes: MAX_DIRECTORY_BYTES }) + end + end end |