Commit d34733ef authored by Rubén Dávila's avatar Rubén Dávila Committed by Robert Speicher
Browse files

Don't show revert button if commit/MR has already been reverted.

parent e8d15f13
......@@ -219,14 +219,20 @@ def revert_branch_name
"revert-#{short_id}"
end
def revert_description
if merged_merge_request
"This reverts merge request #{merged_merge_request.to_reference}"
else
"This reverts commit #{sha}"
end
end
def revert_message
description = if merged_merge_request
"This reverts merge request #{merged_merge_request.to_reference}"
else
"This reverts commit #{sha}"
end
"Revert \"#{title}\"" + "\n\n#{revert_description}"
end
"Revert \"#{title}\"" + "\n\n#{description}"
def reverts_commit?(commit)
description.include?(commit.revert_description)
end
def merge_commit?
......@@ -239,6 +245,14 @@ def merged_merge_request
@merged_merge_request = merge_commit? && MergeRequest.find_by(merge_commit_sha: id)
end
def has_been_reverted?(current_user = nil, noteable = self)
Gitlab::ReferenceExtractor.lazily do
[self, *noteable.notes].flat_map do |note|
note.all_references(current_user).commits
end
end.any? { |commit_ref| commit_ref.reverts_commit?(self) }
end
private
def repo_changes
......
......@@ -533,4 +533,14 @@ def diff_refs
[diff_base_commit, last_commit]
end
def merge_commit
@merge_commit ||= project.commit(merge_commit_sha) if merge_commit_sha
end
def has_been_reverted?(current_user = nil)
if merge_commit
merge_commit.has_been_reverted?(current_user, self)
end
end
end
......@@ -16,7 +16,8 @@
= link_to namespace_project_tree_path(@project.namespace, @project, @commit), class: "btn btn-grouped" do
= icon('files-o')
Browse Files
= revert_commit_link(namespace_project_commit_path(@project.namespace, @project, @commit.id))
- unless @commit.has_been_reverted?(current_user)
= revert_commit_link(namespace_project_commit_path(@project.namespace, @project, @commit.id))
%div
%p
......
......@@ -85,8 +85,8 @@
= spinner
= render 'shared/issuable/sidebar', issuable: @merge_request
- if @merge_request.merge_commit_sha
= render "projects/commit/revert", commit_id: @merge_request.merge_commit_sha, title: @merge_request.title
- if @merge_request.merge_commit && !@merge_request.has_been_reverted?(current_user)
= render "projects/commit/revert", commit_id: @merge_request.merge_commit.id, title: @merge_request.title
:javascript
var merge_request;
......
......@@ -6,7 +6,7 @@
- if @merge_request.merge_event
by #{link_to_member(@project, @merge_request.merge_event.author, avatar: true)}
#{time_ago_with_tooltip(@merge_request.merge_event.created_at)}
- if @merge_request.merge_commit_sha.present?
- unless @merge_request.has_been_reverted?(current_user)
= revert_commit_link(namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm')
%div
- if !@merge_request.source_branch_exists? || (params[:delete_source] == 'true')
......
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