Commit f8b0836c authored by Kev's avatar Kev

Indicate reverted status of a merge request on it's individual page

parent 0795a0fd
......@@ -428,6 +428,10 @@ class Commit
end
def has_been_reverted?(current_user, notes_association = nil)
!!reverting_commit(current_user, notes_association)
end
def reverting_commit(current_user, notes_association = nil)
ext = Gitlab::ReferenceExtractor.new(project, current_user)
notes_association ||= notes_with_associations
......@@ -435,7 +439,7 @@ class Commit
note.all_references(current_user, extractor: ext)
end
ext.commits.any? { |commit_ref| commit_ref.reverts_commit?(self, current_user) }
ext.commits.find { |commit_ref| commit_ref.reverts_commit?(self, current_user) }
end
def change_type_title(user)
......
......@@ -1576,6 +1576,28 @@ class MergeRequest < ApplicationRecord
!merge_commit.has_been_reverted?(current_user, notes_association)
end
def is_reverted?(current_user)
!!reverting_merge_request(current_user)
end
def reverting_merge_request(current_user)
return nil unless merge_commit
return nil unless merged_at
cutoff = merged_at - 1.minute
notes_association = notes_with_associations.where('created_at >= ?', cutoff)
reverting_commit = merge_commit.reverting_commit(current_user, notes_association)
MergeRequestsFinder.new(
current_user,
project_id: project.id,
commit_sha: reverting_commit.sha,
state: 'merged'
).execute.first if reverting_commit
end
def merged_at
strong_memoize(:merged_at) do
next unless merged?
......
......@@ -14,8 +14,13 @@
.detail-page-header-body
.issuable-status-box.status-box{ class: status_box_class(@merge_request) }
= sprite_icon(state_icon_name, css_class: 'd-block d-sm-none')
%span.d-none.d-sm-block
= state_human_name
- if @merge_request.is_reverted?(current_user)
%span.d-none.d-sm-block
= _("Merged")
= link_to '(reverted)', merge_request_path(@merge_request.reverting_merge_request(current_user))
- else
%span.d-none.d-sm-block
= state_human_name
.issuable-meta
#js-issuable-header-warnings
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment