summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-06 13:55:18 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-06 13:55:18 +0300
commit84a8b29fbf17c74ceb04bc7d480278905eea84ac (patch)
treeb06953609b466a35a23c4bd49479130d2d218fe5
parent2ceef7691795958e657f24d78089eecb0eb4a90d (diff)
parent1a17289bd31e30619836b9355982d9317422e65c (diff)
downloadgitlab-ce-84a8b29fbf17c74ceb04bc7d480278905eea84ac.tar.gz
Merge branch 'jacob-carlborg-remove_source_branch_button'
-rw-r--r--app/assets/javascripts/merge_request.js.coffee12
-rw-r--r--app/controllers/projects/merge_requests_controller.rb21
-rw-r--r--app/views/projects/merge_requests/_show.html.haml1
-rw-r--r--app/views/projects/merge_requests/show/_remove_source_branch.html.haml19
4 files changed, 48 insertions, 5 deletions
diff --git a/app/assets/javascripts/merge_request.js.coffee b/app/assets/javascripts/merge_request.js.coffee
index c0f83c93021..235b5c7580c 100644
--- a/app/assets/javascripts/merge_request.js.coffee
+++ b/app/assets/javascripts/merge_request.js.coffee
@@ -58,6 +58,18 @@ class MergeRequest
$('.automerge_widget.can_be_merged').hide()
$('.merge-in-progress').show()
+ this.$('.remove_source_branch').on 'click', ->
+ $('.remove_source_branch_widget').hide()
+ $('.remove_source_branch_in_progress').show()
+
+ this.$(".remove_source_branch").on "ajax:success", (e, data, status, xhr) ->
+ location.reload()
+
+ this.$(".remove_source_branch").on "ajax:error", (e, data, status, xhr) =>
+ this.$('.remove_source_branch_widget').hide()
+ this.$('.remove_source_branch_in_progress').hide()
+ this.$('.remove_source_branch_widget.failed').show()
+
activateTab: (action) ->
this.$('.nav-tabs li').removeClass 'active'
this.$('.tab-content').hide()
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index c090dd917c2..d6402dd217d 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -211,9 +211,25 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request_diff = @merge_request.merge_request_diff
@allowed_to_merge = allowed_to_merge?
@show_merge_controls = @merge_request.open? && @commits.any? && @allowed_to_merge
+ @allowed_to_remove_source_branch = allowed_to_remove_source_branch?
+ @source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name)
end
def allowed_to_merge?
+ allowed_to_push_code?(project)
+ end
+
+ def invalid_mr
+ # Render special view for MR with removed source or target branch
+ render 'invalid'
+ end
+
+ def allowed_to_remove_source_branch?
+ allowed_to_push_code?(@merge_request.source_project) &&
+ !@merge_request.disallow_source_branch_removal?
+ end
+
+ def allowed_to_push_code?(project)
action = if project.protected_branch?(@merge_request.target_branch)
:push_code_to_protected_branches
else
@@ -222,9 +238,4 @@ class Projects::MergeRequestsController < Projects::ApplicationController
can?(current_user, action, @project)
end
-
- def invalid_mr
- # Render special view for MR with removed source or target branch
- render 'invalid'
- end
end
diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml
index 7a21c0dd069..5da5c8a44f7 100644
--- a/app/views/projects/merge_requests/_show.html.haml
+++ b/app/views/projects/merge_requests/_show.html.haml
@@ -7,6 +7,7 @@
= render "projects/merge_requests/show/mr_accept"
- else
= render "projects/merge_requests/show/no_accept"
+ = render "projects/merge_requests/show/remove_source_branch"
- if @merge_request.source_project.gitlab_ci?
= render "projects/merge_requests/show/mr_ci"
= render "projects/merge_requests/show/commits"
diff --git a/app/views/projects/merge_requests/show/_remove_source_branch.html.haml b/app/views/projects/merge_requests/show/_remove_source_branch.html.haml
new file mode 100644
index 00000000000..b95f7a4667d
--- /dev/null
+++ b/app/views/projects/merge_requests/show/_remove_source_branch.html.haml
@@ -0,0 +1,19 @@
+- if @source_branch.blank?
+ .bs-callout.bs-callout-info
+ Source branch has been removed
+
+- elsif @allowed_to_remove_source_branch && @merge_request.merged?
+ .remove_source_branch_widget
+ .alert.alert-info
+ = link_to project_branch_path(@merge_request.source_project, @source_branch), remote: true, method: :delete, class: "btn btn-primary remove_source_branch" do
+ %i.icon-remove
+ Remove Source Branch
+
+ .remove_source_branch_widget.failed.hide
+ .alert.alert-error Failed to remove source branch '#{@merge_request.source_branch}'
+
+ .remove_source_branch_in_progress.hide
+ .bs-callout.bs-callout-info
+ %i.icon-refresh.icon-spin
+ &nbsp;
+ Removing source branch '#{@merge_request.source_branch}'. Please wait. Page will be automatically reloaded. &nbsp;