Skip to content

Suggestions: use template from target project instead of source project

What does this MR do and why?

Fixes #354880 (closed).

For MRs created from fork projects with different suggestion template than target project, there is currently a discrepancy in commit message. Frontend shows values from target project, however the actual commit ends up with values from source project (fork). It uses source project's template, and variables %{project_name} and %{project_path} also use values from source project.

This MR fixes that - suggestions will now use target's project template, and variables %{project_name} and %{project_path} will use target's project name and path as well.

Screenshots or screen recordings

Target project setting:

image

Preview:

image

Result commit BEFORE my changes:

image

AFTER:

image

Note: there is still an unrelated discrepancy in %{project_path} (it uses path with namespace in frontend preview, but path without namespace in end result) - I've addressed it in a comment.

How to set up and validate locally

  1. Create or find a project and fork of the project.
  2. Change template in target project - https://docs.gitlab.com/ee/user/project/merge_requests/reviews/suggestions.html#configure-the-commit-message-for-applied-suggestions - to different than source project. It could also use %{project_name} variable.
  3. Create a MR from fork to main project.
  4. Add a comment with suggestion.
  5. Verify that end commit is the same as shown in preview, and that it uses target's project.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Piotr Stankowski

Merge request reports