Recreate default success message after commiting change
What does this MR do and why?
This MR is a chunk of work I started in !202756 (closed). I've realised I'll have to cover a couple of scenarios that previously the controller was taking care. Below you can find a breakdown how I plan to split the work:
| MR # | Scope | Status |
|---|---|---|
| 1 | Uses rest API to submit data | |
| 2 | Reintroduce notifications | |
| 3 | Editing file name is possible | |
| 4 | File size validation | |
| 5 | Handle fork workflow |
This MR recreates flash notice triggered by create_commit inside update. create_commit calls update_flash_notice. Here's the exact code we want to be handled with alert.js:
def update_flash_notice(success_notice, success_path)
changes_link = ActionController::Base.helpers.link_to _('changes'), success_path, class: 'gl-link'
default_message = safe_format(_("Your %{changes_link} have been committed successfully."),
changes_link: changes_link)
flash[:notice] = success_notice || default_message
if create_merge_request?
flash[:notice] =
if merge_request_exists?
nil
else
mr_message =
if @different_project # rubocop:disable Gitlab/ModuleWithInstanceVariables
_("You can now submit a merge request to get this change into the original project.")
else
_("You can now submit a merge request to get this change into the original branch.")
end
flash[:notice] += " #{mr_message}"
end
end
end
I decided not to reimplement this function:
def create_merge_request?
# Even if the field is set, if we're checking the same branch
# as the target branch in the same project,
# we don't want to create a merge request.
# FIXME: We should use either 1 or true, not both.
ActiveModel::Type::Boolean.new.cast(params[:create_merge_request]) &&
(@different_project || @start_branch != @branch_name) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
My reasons:
-
@different_projectis essentiallycanPushToBranchand I will work in a separate MR on the whole fork workflow -
@start_branch != @branch_name- this is implied withthis.formData.create_merge_requestyou can only choose that when a different branch than default is selected.
Note
For some reason, the extra message to submit the MR wasn't shown when editing with controller.
I decided to copy it over, but I'm interesting what @alyssatrinh and @ms.mondrian have to say about it, since they were working on improving the UX around the submit edit modal. Maybe we don't need it, as the user had to check off the option to create the MR?
References
Screenshots or screen recordings
| Before | After |
|---|---|
| Screen_Recording_2025-10-02_at_15.24.27 | Screen_Recording_2025-10-02_at_15.22.20 |
| Screen_Recording_2025-10-02_at_15.25.00 | Screen_Recording_2025-10-02_at_15.23.05 |
How to set up and validate locally
-
In rails console enable the feature flag
Feature.enable(:blob_edit_refactor) -
Go to Project / Repository
-
Choose a file to edit in single file editor.
-
Check the following scenarios:
- commit changes directly to master
- commit changes to a new branch without opening an MR
- Validate you can perform both actions and an alert is show to you after the edit with notification that you successfully edited the file.
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.
Related to #509968