Inherit the picked merge request description on cherry-pick

What does this MR do and why?

Cherry-picking a merged merge request with Start a new merge request with these changes lands on the new merge request form, and the form starts from the description template. The description of the change that was picked is gone, and whoever opens the pick has to find it and copy it over by hand.

This adds a Copy merge request description checkbox to the cherry-pick dialog. It appears only while a new merge request is being started and is unticked by default, so nothing changes for anyone who does not ask for it.

  • Projects::CommitController resolves the merge request that recorded the commit and puts its id in the redirect, but only when the box is ticked. It has to happen there: the action runs in the project the commit came from, which a pick into another project or into a fork no longer knows about. The id travels rather than the iid, since an iid repeats across projects.
  • One scope covers every way a merge request records that commit — a merge commit, a squash commit, or, for a fast-forward merge where neither exists, the merged commit itself. A fast-forward merge keeps the sha of the source branch, so several merge requests can record the same sha; the oldest is used, the merge request the change came from rather than a backport of it.
  • MergeRequests::BuildService reads the id out of the params before #process_params, since no merge request attribute matches it, and the id is permitted on the new action alone. The description is assigned in #assign_title_and_description, in place of the template: a picked description is content rather than a template, so it keeps any %{...} it contains and never reaches the placeholder replacement. An explicit description still wins over the inherited one.
  • Whoever opens the form could put any id in the query string, so the read permission is checked on whatever it resolves to.

Picking a plain commit finds no merge request and leaves both the redirect and the template exactly as they were.

Closes #608074

How to set up and validate locally

  1. Add a default merge request template to a project (.gitlab/merge_request_templates/default.md).
  2. Open a merge request against the default branch, give it a description, and merge it.
  3. On the merged merge request, select Cherry-pick. Leave Start a new merge request with these changes ticked and tick Copy merge request description.
  4. Select Cherry-pick. The form is prefilled with the description of the merge request you picked.
  5. Repeat without ticking Copy merge request description, and confirm the form falls back to the description template.
  6. Cherry-pick a plain commit and confirm the checkbox changes nothing, since no merge request recorded it.

Coverage:

bundle exec rspec spec/requests/projects/commit_controller_spec.rb \
  spec/requests/projects/merge_requests/creations_controller_spec.rb \
  spec/services/merge_requests/build_service_spec.rb
yarn jest spec/frontend/projects/commit/components/form_modal_spec.js

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 Viktor Chekryzhov

Merge request reports

Loading
Loading