Commit f8114954292e3551b61406438d41cd05a6f9ae31
1 parent
8fb9dccd
Exists in
spb-stable
and in
3 other branches
Add button for removing source branch for merged MR's.
Showing
5 changed files
with
47 additions
and
6 deletions
Show diff stats
app/assets/javascripts/merge_requests.js.coffee
... | ... | @@ -57,6 +57,18 @@ class MergeRequest |
57 | 57 | $('.automerge_widget.can_be_merged').hide() |
58 | 58 | $('.merge-in-progress').show() |
59 | 59 | |
60 | + this.$('.remove_source_branch').on 'click', -> | |
61 | + $('.remove_source_branch_widget').hide() | |
62 | + $('.remove_source_branch_in_progress').show() | |
63 | + | |
64 | + this.$(".remove_source_branch").on "ajax:success", (e, data, status, xhr) -> | |
65 | + location.reload() | |
66 | + | |
67 | + this.$(".remove_source_branch").on "ajax:error", (e, data, status, xhr) => | |
68 | + this.$('.remove_source_branch_widget').hide() | |
69 | + this.$('.remove_source_branch_in_progress').hide() | |
70 | + this.$('.remove_source_branch_widget.failed').show() | |
71 | + | |
60 | 72 | activateTab: (action) -> |
61 | 73 | this.$('.nav-tabs li').removeClass 'active' |
62 | 74 | this.$('.tab-content').hide() | ... | ... |
app/assets/stylesheets/sections/merge_requests.scss
app/controllers/projects/merge_requests_controller.rb
... | ... | @@ -199,6 +199,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
199 | 199 | @commits = @merge_request.commits |
200 | 200 | |
201 | 201 | @allowed_to_merge = allowed_to_merge? |
202 | + @allowed_to_remove_source_branch = allowed_to_remove_source_branch? | |
203 | + @source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name) | |
202 | 204 | @show_merge_controls = @merge_request.opened? && @commits.any? && @allowed_to_merge |
203 | 205 | |
204 | 206 | @target_type = :merge_request |
... | ... | @@ -206,6 +208,19 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
206 | 208 | end |
207 | 209 | |
208 | 210 | def allowed_to_merge? |
211 | + allowed_to_push_code?(project) | |
212 | + end | |
213 | + | |
214 | + def invalid_mr | |
215 | + # Render special view for MR with removed source or target branch | |
216 | + render 'invalid' | |
217 | + end | |
218 | + | |
219 | + def allowed_to_remove_source_branch? | |
220 | + allowed_to_push_code?(@merge_request.source_project) | |
221 | + end | |
222 | + | |
223 | + def allowed_to_push_code? (project) | |
209 | 224 | action = if project.protected_branch?(@merge_request.target_branch) |
210 | 225 | :push_code_to_protected_branches |
211 | 226 | else |
... | ... | @@ -214,9 +229,4 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
214 | 229 | |
215 | 230 | can?(current_user, action, @project) |
216 | 231 | end |
217 | - | |
218 | - def invalid_mr | |
219 | - # Render special view for MR with removed source or target branch | |
220 | - render 'invalid' | |
221 | - end | |
222 | 232 | 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,18 @@ |
1 | +- if @source_branch.blank? | |
2 | + .alert.alert-info Source branch has been removed | |
3 | + | |
4 | +- elsif @allowed_to_remove_source_branch && @merge_request.merged? | |
5 | + .remove_source_branch_widget | |
6 | + .alert.alert-info | |
7 | + = link_to project_branch_path(@merge_request.source_project, @source_branch), remote: true, method: :delete, class: "btn remove_source_branch" do | |
8 | + %i.icon-remove | |
9 | + Remove Source Branch | |
10 | + | |
11 | + .remove_source_branch_widget.failed.hide | |
12 | + .alert.alert-error Failed to remove source branch '#{@merge_request.source_branch}' | |
13 | + | |
14 | + .remove_source_branch_in_progress.hide | |
15 | + %span.cgray | |
16 | + %i.icon-refresh.icon-spin | |
17 | + | |
18 | + Removing source branch '#{@merge_request.source_branch}'. Please wait. Page will be automatically reloaded. | |
0 | 19 | \ No newline at end of file | ... | ... |