Cap the context commits finder limit at the UI default

What does this MR do and why?

When you add previously merged commits to a merge request, the Add or remove previously merged commits modal lists the most recent commits on the target branch. The modal loads them from /-/merge_requests/:iid/context_commits.json, which returns 40 commits by default. It also accepts a limit parameter that can ask for any number of commits.

The modal never sends limit, so it always shows 40. This MR makes the endpoint match: limit now has to be between 1 and 40. Values outside that range are clamped to the nearest bound.

The endpoint is only used by the modal. The REST API for context commits doesn't use it and isn't affected.

limit sent Before After
none 40 40 (unchanged)
1 to 40 as sent as sent (unchanged)
above 40 as sent 40
below 1 or non-numeric as sent 1

Why no feature flag

  • The modal's behaviour doesn't change: it doesn't send limit, so it keeps getting 40 commits.
  • On GitLab.com, no request to this endpoint sent limit in the last 4 weeks (logs).
  • The endpoint isn't documented.

References

Screenshots or screen recordings

Not applicable: no UI change. The modal doesn't send limit, so it always gets the default of 40.

How to set up and validate locally

  1. Open a merge request that you can update, in a project with more than 40 commits on the target branch.
  2. While signed in, visit <merge request URL>/context_commits.json?limit=100. The response has at most 40 commits.
  3. Visit <merge request URL>/context_commits.json?limit=0. The response has at most 1 commit.
  4. On the merge request's Commits tab, select Add previously merged commits. The modal lists commits as before.

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 Eugenia Grieff

Merge request reports

Loading
Loading