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

More updates from the last code review.

parent 78d3444f
...@@ -11,7 +11,6 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -11,7 +11,6 @@ class Projects::CommitController < Projects::ApplicationController
before_action :authorize_read_commit_status!, only: [:builds] before_action :authorize_read_commit_status!, only: [:builds]
before_action :commit before_action :commit
before_action :define_show_vars, only: [:show, :builds] before_action :define_show_vars, only: [:show, :builds]
before_action :assign_revert_commit_vars, only: [:revert]
before_action :authorize_edit_tree!, only: [:revert] before_action :authorize_edit_tree!, only: [:revert]
def show def show
...@@ -60,6 +59,8 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -60,6 +59,8 @@ class Projects::CommitController < Projects::ApplicationController
end end
def revert def revert
assign_revert_commit_vars
return render_404 if @target_branch.blank? return render_404 if @target_branch.blank?
create_commit(Commits::RevertService, success_notice: "The #{revert_type_title} has been successfully reverted.", create_commit(Commits::RevertService, success_notice: "The #{revert_type_title} has been successfully reverted.",
......
...@@ -242,7 +242,7 @@ class Commit ...@@ -242,7 +242,7 @@ class Commit
def merged_merge_request def merged_merge_request
return @merged_merge_request if defined?(@merged_merge_request) return @merged_merge_request if defined?(@merged_merge_request)
@merged_merge_request = merge_commit? && project.merge_requests.find_by(merge_commit_sha: id) @merged_merge_request = project.merge_requests.find_by(merge_commit_sha: id) if merge_commit?
end end
def has_been_reverted?(current_user = nil, noteable = self) def has_been_reverted?(current_user = nil, noteable = self)
......
...@@ -538,9 +538,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -538,9 +538,7 @@ class MergeRequest < ActiveRecord::Base
@merge_commit ||= project.commit(merge_commit_sha) if merge_commit_sha @merge_commit ||= project.commit(merge_commit_sha) if merge_commit_sha
end end
def has_been_reverted?(current_user = nil) def can_be_reverted?(current_user = nil)
if merge_commit merge_commit && !merge_commit.has_been_reverted?(current_user, self)
merge_commit.has_been_reverted?(current_user, self)
end
end end
end end
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
= spinner = spinner
= render 'shared/issuable/sidebar', issuable: @merge_request = render 'shared/issuable/sidebar', issuable: @merge_request
- if @merge_request.merge_commit && !@merge_request.has_been_reverted?(current_user) - if @merge_request.can_be_reverted?
= render "projects/commit/revert", commit: @merge_request.merge_commit, title: @merge_request.title = render "projects/commit/revert", commit: @merge_request.merge_commit, title: @merge_request.title
:javascript :javascript
......
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
%i.fa.fa-pencil-square-o %i.fa.fa-pencil-square-o
Edit Edit
- if @merge_request.closed? - if @merge_request.closed?
= link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: 'btn btn-nr btn-grouped btn-reopen reopen-mr-link', title: "Reopen merge request" = link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: 'btn btn-nr btn-grouped btn-reopen reopen-mr-link', title: 'Reopen merge request'
...@@ -7,28 +7,19 @@ ...@@ -7,28 +7,19 @@
by #{link_to_member(@project, @merge_request.merge_event.author, avatar: true)} by #{link_to_member(@project, @merge_request.merge_event.author, avatar: true)}
#{time_ago_with_tooltip(@merge_request.merge_event.created_at)} #{time_ago_with_tooltip(@merge_request.merge_event.created_at)}
%div %div
- revert_button = capture_haml do
- if @merge_request.merge_commit && !@merge_request.has_been_reverted?(current_user)
= revert_commit_link(@merge_request.merge_commit, namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm')
- if !@merge_request.source_branch_exists? || (params[:delete_source] == 'true') - if !@merge_request.source_branch_exists? || (params[:delete_source] == 'true')
%p %p
The changes were merged into The changes were merged into
#{link_to @merge_request.target_branch, namespace_project_commits_path(@project.namespace, @project, @merge_request.target_branch), class: "label-branch"}. #{link_to @merge_request.target_branch, namespace_project_commits_path(@project.namespace, @project, @merge_request.target_branch), class: "label-branch"}.
The source branch has been removed. The source branch has been removed.
- if revert_button.present? = render 'projects/merge_requests/widget/merged_buttons'
.btn-group= revert_button
- elsif @merge_request.can_remove_source_branch?(current_user) - elsif @merge_request.can_remove_source_branch?(current_user)
.remove_source_branch_widget .remove_source_branch_widget
%p %p
The changes were merged into The changes were merged into
#{link_to @merge_request.target_branch, namespace_project_commits_path(@project.namespace, @project, @merge_request.target_branch), class: "label-branch"}. #{link_to @merge_request.target_branch, namespace_project_commits_path(@project.namespace, @project, @merge_request.target_branch), class: "label-branch"}.
You can remove the source branch now. You can remove the source branch now.
.btn-group = render 'projects/merge_requests/widget/merged_buttons', source_branch_exists: true
= link_to namespace_project_branch_path(@merge_request.source_project.namespace, @merge_request.source_project, @merge_request.source_branch), remote: true, method: :delete, class: "btn btn-default btn-grouped btn-sm remove_source_branch" do
%i.fa.fa-trash-o
Remove Source Branch
= revert_button
.remove_source_branch_widget.failed.hide .remove_source_branch_widget.failed.hide
%p %p
Failed to remove source branch '#{@merge_request.source_branch}'. Failed to remove source branch '#{@merge_request.source_branch}'.
......
- source_branch_exists = local_assigns.fetch(:source_branch_exists, false)
- mr_can_be_reverted = @merge_request.can_be_reverted?
- if source_branch_exists || mr_can_be_reverted
.btn-group
- if source_branch_exists
= link_to namespace_project_branch_path(@merge_request.source_project.namespace, @merge_request.source_project, @merge_request.source_branch), remote: true, method: :delete, class: "btn btn-default btn-grouped btn-sm remove_source_branch" do
= icon('trash-o')
Remove Source Branch
- if mr_can_be_reverted
= revert_commit_link(@merge_request.merge_commit, namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm')
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