Commit 1a17289bd31e30619836b9355982d9317422e65c
Exists in
spb-stable
and in
3 other branches
Merge branch 'remove_source_branch_button' of https://github.com/jacob-carlborg/…
…gitlabhq into jacob-carlborg-remove_source_branch_button Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: app/assets/javascripts/merge_requests.js.coffee app/assets/stylesheets/sections/merge_requests.scss app/controllers/projects/merge_requests_controller.rb
Showing
4 changed files
with
48 additions
and
5 deletions
Show diff stats
app/assets/javascripts/merge_request.js.coffee
... | ... | @@ -58,6 +58,18 @@ class MergeRequest |
58 | 58 | $('.automerge_widget.can_be_merged').hide() |
59 | 59 | $('.merge-in-progress').show() |
60 | 60 | |
61 | + this.$('.remove_source_branch').on 'click', -> | |
62 | + $('.remove_source_branch_widget').hide() | |
63 | + $('.remove_source_branch_in_progress').show() | |
64 | + | |
65 | + this.$(".remove_source_branch").on "ajax:success", (e, data, status, xhr) -> | |
66 | + location.reload() | |
67 | + | |
68 | + this.$(".remove_source_branch").on "ajax:error", (e, data, status, xhr) => | |
69 | + this.$('.remove_source_branch_widget').hide() | |
70 | + this.$('.remove_source_branch_in_progress').hide() | |
71 | + this.$('.remove_source_branch_widget.failed').show() | |
72 | + | |
61 | 73 | activateTab: (action) -> |
62 | 74 | this.$('.nav-tabs li').removeClass 'active' |
63 | 75 | this.$('.tab-content').hide() | ... | ... |
app/controllers/projects/merge_requests_controller.rb
... | ... | @@ -211,9 +211,25 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
211 | 211 | @merge_request_diff = @merge_request.merge_request_diff |
212 | 212 | @allowed_to_merge = allowed_to_merge? |
213 | 213 | @show_merge_controls = @merge_request.open? && @commits.any? && @allowed_to_merge |
214 | + @allowed_to_remove_source_branch = allowed_to_remove_source_branch? | |
215 | + @source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name) | |
214 | 216 | end |
215 | 217 | |
216 | 218 | def allowed_to_merge? |
219 | + allowed_to_push_code?(project) | |
220 | + end | |
221 | + | |
222 | + def invalid_mr | |
223 | + # Render special view for MR with removed source or target branch | |
224 | + render 'invalid' | |
225 | + end | |
226 | + | |
227 | + def allowed_to_remove_source_branch? | |
228 | + allowed_to_push_code?(@merge_request.source_project) && | |
229 | + !@merge_request.disallow_source_branch_removal? | |
230 | + end | |
231 | + | |
232 | + def allowed_to_push_code?(project) | |
217 | 233 | action = if project.protected_branch?(@merge_request.target_branch) |
218 | 234 | :push_code_to_protected_branches |
219 | 235 | else |
... | ... | @@ -222,9 +238,4 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
222 | 238 | |
223 | 239 | can?(current_user, action, @project) |
224 | 240 | end |
225 | - | |
226 | - def invalid_mr | |
227 | - # Render special view for MR with removed source or target branch | |
228 | - render 'invalid' | |
229 | - end | |
230 | 241 | end | ... | ... |
app/views/projects/merge_requests/_show.html.haml
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | = render "projects/merge_requests/show/mr_accept" |
8 | 8 | - else |
9 | 9 | = render "projects/merge_requests/show/no_accept" |
10 | + = render "projects/merge_requests/show/remove_source_branch" | |
10 | 11 | - if @merge_request.source_project.gitlab_ci? |
11 | 12 | = render "projects/merge_requests/show/mr_ci" |
12 | 13 | = render "projects/merge_requests/show/commits" | ... | ... |
app/views/projects/merge_requests/show/_remove_source_branch.html.haml
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +- if @source_branch.blank? | |
2 | + .bs-callout.bs-callout-info | |
3 | + Source branch has been removed | |
4 | + | |
5 | +- elsif @allowed_to_remove_source_branch && @merge_request.merged? | |
6 | + .remove_source_branch_widget | |
7 | + .alert.alert-info | |
8 | + = link_to project_branch_path(@merge_request.source_project, @source_branch), remote: true, method: :delete, class: "btn btn-primary remove_source_branch" do | |
9 | + %i.icon-remove | |
10 | + Remove Source Branch | |
11 | + | |
12 | + .remove_source_branch_widget.failed.hide | |
13 | + .alert.alert-error Failed to remove source branch '#{@merge_request.source_branch}' | |
14 | + | |
15 | + .remove_source_branch_in_progress.hide | |
16 | + .bs-callout.bs-callout-info | |
17 | + %i.icon-refresh.icon-spin | |
18 | + | |
19 | + Removing source branch '#{@merge_request.source_branch}'. Please wait. Page will be automatically reloaded. | ... | ... |