Add "Delete source branch" button to closed merge requests
What does this MR do and why?
This MR adds a "Delete Source Branch" button to the closed MR widget.
- Extracts the post-merge delete source branch logic into a reusable
mixin
sourceBranchRemovalMixin, and uses it in bothMRWidgetMergedandMRWidgetClosed. - Fixes a bug in the merged MR widget where the "Delete source branch"
button was not removed after a successful deletion. The button now
disappears immediately by setting
mr.sourceBranchRemoved = truedirectly from the API response, rather than relying onMRWidgetUpdateRequestedwhich triggered a GraphQL refetch that did not includesourceBranchExists. - A new analytics event
i_code_review_post_close_delete_branchis introduced to track usage separately from the post-merge equivalent.
References
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
Use the following snippet to create 2 merge requests quickly:
project = Project.find_by_full_path('x')
user = project.first_owner
repo = project.repository
ts = Time.now.to_i
2.times do |i|
branch_name = "test-delete-source-branch-#{ts}-#{i + 1}"
repo.create_branch(branch_name, project.default_branch)
repo.create_file(
user,
"test-#{ts}-#{i + 1}.txt",
"test content #{i + 1}",
message: "Add test file #{i + 1}",
branch_name: branch_name,
)
mr = MergeRequests::CreateService.new(
project: project,
current_user: user,
params: {
title: "Test delete source branch #{i + 1}",
source_branch: branch_name,
target_branch: project.default_branch,
force_remove_source_branch: '0',
},
).execute
puts "Created MR !#{mr.iid}: #{mr.title} (#{mr.source_branch})"
endTest the change with a closed MR:
- Close one of the merge requests
- Wait a few moments for the MR widget to update - the "Delete Source Branch" button should appear.
- Click the "Delete Source Branch" button - if successful the button will disappear, and you will see an XHR request to
DELETE http://gdk.test:3000/<group>/<project>/-/branches/<branch>return a200/{"message":"Branch was deleted"}
To ensure that the change did not break existing functionality, test the change with a merged MR:
- Merge one of the merge requests.
- Wait a few moments for the MR widget to update - the "Delete Source Branch" button should appear.
- Click the "Delete Source Branch" button - if successful the button will disappear, and you will see an XHR request to
DELETE http://gdk.test:3000/<group>/<project>/-/branches/<branch>return a200/{"message":"Branch was deleted"}
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Anton Smith

