Skip to content

Fix merge request redirects going to /commits page

Stan Hu requested to merge sh-fix-mr-redirects into master

When a merge request is redirected to a new project, Rails attempts to construct the proper URL in url_for by finding the first route that matches the given parameters:

  1. controller -> projects/merge_requests
  2. action -> show
  3. namespace_id
  4. project_id
  5. id

In this example, /*namespace_id/:project_id/commits/*id matched instead of /*namespace_id/:project_id/merge_requests/:id.

This happens because the Rails resources block defines all the standard #index, #show, #update, etc. routes after the block runs.

We fixed this issue by explicitly specifying the merge request #show as the first route.

This is similar to #31357 (closed), except the solution is a bit simpler because the backend appears to set a tab query string, which allows the redirected route to end up in the right place. For example, visiting the old /merge_requests/:id/commits appears to cause a redirection to /merge_requests/:id/?tab=commits, which does the right thing.

Edited by Stan Hu

Merge request reports