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:
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb85
1 files changed, 40 insertions, 45 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 7e1898e7142..2280c5280d5 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -17,6 +17,7 @@ class MergeRequest < ApplicationRecord
include FromUnion
include DeprecatedAssignee
include ShaAttribute
+ include IgnorableColumns
sha_attribute :squash_commit_sha
@@ -26,8 +27,6 @@ class MergeRequest < ApplicationRecord
SORTING_PREFERENCE_FIELD = :merge_requests_sort
- prepend_if_ee('::EE::MergeRequest') # rubocop: disable Cop/InjectEnterpriseEditionModule
-
belongs_to :target_project, class_name: "Project"
belongs_to :source_project, class_name: "Project"
belongs_to :merge_user, class_name: "User"
@@ -72,6 +71,15 @@ class MergeRequest < ApplicationRecord
has_many :merge_request_assignees
has_many :assignees, class_name: "User", through: :merge_request_assignees
+ has_many :user_mentions, class_name: "MergeRequestUserMention"
+
+ has_many :deployment_merge_requests
+
+ # These are deployments created after the merge request has been merged, and
+ # the merge request was tracked explicitly (instead of implicitly using a CI
+ # build).
+ has_many :deployments,
+ through: :deployment_merge_requests
KNOWN_MERGE_PARAMS = [
:auto_merge_strategy,
@@ -103,7 +111,7 @@ class MergeRequest < ApplicationRecord
super + [:merged, :locked]
end
- state_machine :state_id, initial: :opened do
+ state_machine :state_id, initial: :opened, initialize: false do
event :close do
transition [:opened] => :closed
end
@@ -199,6 +207,9 @@ class MergeRequest < ApplicationRecord
scope :by_milestone, ->(milestone) { where(milestone_id: milestone) }
scope :of_projects, ->(ids) { where(target_project_id: ids) }
scope :from_project, ->(project) { where(source_project_id: project.id) }
+ scope :from_and_to_forks, ->(project) do
+ where('source_project_id <> target_project_id AND (source_project_id = ? OR target_project_id = ?)', project.id, project.id)
+ end
scope :merged, -> { with_state(:merged) }
scope :closed_and_merged, -> { with_states(:closed, :merged) }
scope :open_and_closed, -> { with_states(:opened, :closed) }
@@ -228,7 +239,9 @@ class MergeRequest < ApplicationRecord
with_state(:opened).where(auto_merge_enabled: true)
end
- after_save :keep_around_commit
+ ignore_column :state, remove_with: '12.7', remove_after: '2019-12-22'
+
+ after_save :keep_around_commit, unless: :importing?
alias_attribute :project, :target_project
alias_attribute :project_id, :target_project_id
@@ -241,6 +254,9 @@ class MergeRequest < ApplicationRecord
alias_attribute :auto_merge_enabled, :merge_when_pipeline_succeeds
alias_method :issuing_parent, :target_project
+ delegate :active?, to: :head_pipeline, prefix: true, allow_nil: true
+ delegate :success?, to: :actual_head_pipeline, prefix: true, allow_nil: true
+
RebaseLockTimeout = Class.new(StandardError)
REBASE_LOCK_MESSAGE = _("Failed to enqueue the rebase operation, possibly due to a long-lived transaction. Try again later.")
@@ -260,7 +276,7 @@ class MergeRequest < ApplicationRecord
def self.recent_target_branches(limit: 100)
group(:target_branch)
.select(:target_branch)
- .reorder('MAX(merge_requests.updated_at) DESC')
+ .reorder(arel_table[:updated_at].maximum.desc)
.limit(limit)
.pluck(:target_branch)
end
@@ -414,15 +430,6 @@ class MergeRequest < ApplicationRecord
limit ? shas.take(limit) : shas
end
- # Returns true if there are commits that match at least one commit SHA.
- def includes_any_commits?(shas)
- if persisted?
- merge_request_diff.commits_by_shas(shas).exists?
- else
- (commit_shas & shas).present?
- end
- end
-
def supports_suggestion?
true
end
@@ -1060,7 +1067,7 @@ class MergeRequest < ApplicationRecord
# Returns the oldest multi-line commit message, or the MR title if none found
def default_squash_commit_message
strong_memoize(:default_squash_commit_message) do
- commits.without_merge_commits.reverse.find(&:description?)&.safe_message || title
+ recent_commits.without_merge_commits.reverse_each.find(&:description?)&.safe_message || title
end
end
@@ -1143,26 +1150,6 @@ class MergeRequest < ApplicationRecord
actual_head_pipeline.environments
end
- def state_human_name
- if merged?
- "Merged"
- elsif closed?
- "Closed"
- else
- "Open"
- end
- end
-
- def state_icon_name
- if merged?
- "git-merge"
- elsif closed?
- "close"
- else
- "issue-open-m"
- end
- end
-
def fetch_ref!
target_project.repository.fetch_source_branch!(source_project.repository, source_branch, ref_path)
end
@@ -1239,16 +1226,8 @@ class MergeRequest < ApplicationRecord
end
def all_pipelines
- return Ci::Pipeline.none unless source_project
-
- shas = all_commit_shas
-
strong_memoize(:all_pipelines) do
- Ci::Pipeline.from_union(
- [source_project.ci_pipelines.merge_request_pipelines(self, shas),
- source_project.ci_pipelines.detached_merge_request_pipelines(self, shas),
- source_project.ci_pipelines.triggered_for_branch(source_branch).for_sha(shas)],
- remove_duplicates: false).sort_by_merge_request_pipelines
+ MergeRequest::Pipelines.new(self).all
end
end
@@ -1444,6 +1423,12 @@ class MergeRequest < ApplicationRecord
true
end
+ def pipeline_coverage_delta
+ if base_pipeline&.coverage && head_pipeline&.coverage
+ '%.2f' % (head_pipeline.coverage.to_f - base_pipeline.coverage.to_f)
+ end
+ end
+
def base_pipeline
@base_pipeline ||= project.ci_pipelines
.order(id: :desc)
@@ -1499,6 +1484,14 @@ class MergeRequest < ApplicationRecord
all_pipelines.for_sha_or_source_sha(diff_head_sha).first
end
+ def etag_caching_enabled?
+ true
+ end
+
+ def recent_visible_deployments
+ deployments.visible.includes(:environment).order(id: :desc).limit(10)
+ end
+
private
def with_rebase_lock
@@ -1521,7 +1514,7 @@ class MergeRequest < ApplicationRecord
end
end
rescue ActiveRecord::LockWaitTimeout => e
- Gitlab::Sentry.track_acceptable_exception(e)
+ Gitlab::ErrorTracking.track_exception(e)
raise RebaseLockTimeout, REBASE_LOCK_MESSAGE
end
@@ -1543,3 +1536,5 @@ class MergeRequest < ApplicationRecord
Gitlab::EtagCaching::Store.new.touch(key)
end
end
+
+MergeRequest.prepend_if_ee('::EE::MergeRequest')