Commit a28eef1d authored by Rubén Dávila's avatar Rubén Dávila Committed by Robert Speicher

Update copy and URLs used when reverting MRs.

parent 38752d15
...@@ -62,13 +62,32 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -62,13 +62,32 @@ class Projects::CommitController < Projects::ApplicationController
def revert def revert
return render_404 if @target_branch.blank? return render_404 if @target_branch.blank?
create_commit(Commits::RevertService, success_notice: "The commit has been successfully reverted.", create_commit(Commits::RevertService, success_notice: "The #{revert_type_title} has been successfully reverted.",
success_path: namespace_project_commits_path(@project.namespace, @project, @target_branch), success_path: successful_revert_path, failure_path: failed_revert_path)
failure_path: namespace_project_commit_path(@project.namespace, @project, params[:id]))
end end
private private
def revert_type_title
@commit.merged_merge_request ? 'merge request' : 'commit'
end
def successful_revert_path
return referenced_merge_request_url if @commit.merged_merge_request
namespace_project_commits_url(@project.namespace, @project, @target_branch)
end
def failed_revert_path
return referenced_merge_request_url if @commit.merged_merge_request
namespace_project_commit_url(@project.namespace, @project, params[:id])
end
def referenced_merge_request_url
namespace_project_merge_request_url(@project.namespace, @project, @commit.merged_merge_request)
end
def commit def commit
@commit ||= @project.commit(params[:id]) @commit ||= @project.commit(params[:id])
end end
...@@ -99,6 +118,7 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -99,6 +118,7 @@ class Projects::CommitController < Projects::ApplicationController
@mr_target_branch = @target_branch @mr_target_branch = @target_branch
@commit_params = { @commit_params = {
commit: @commit, commit: @commit,
revert_type_title: revert_type_title,
create_merge_request: params[:create_merge_request].present? || different_project? create_merge_request: params[:create_merge_request].present? || different_project?
} }
end end
......
...@@ -227,6 +227,12 @@ class Commit ...@@ -227,6 +227,12 @@ class Commit
parents.size > 1 parents.size > 1
end end
def merged_merge_request
return @merged_merge_request if defined?(@merged_merge_request)
@merged_merge_request = is_a_merge_commit? && MergeRequest.where(merge_commit_sha: id).first
end
private private
def repo_changes def repo_changes
......
...@@ -14,7 +14,7 @@ module Commits ...@@ -14,7 +14,7 @@ module Commits
if commit if commit
success success
else else
error("Sorry, we cannot revert this commit automatically. error("Sorry, we cannot revert this #{params[:revert_type_title]} automatically.
It may have already been reverted, or a more recent commit may It may have already been reverted, or a more recent commit may
have updated some of its content.") have updated some of its content.")
end end
......
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