Skip to content

Update the changes tab count badge when the diff is loaded

Thomas Randolph requested to merge tor/defect/changes-count-incorrect into master

What does this MR do and why?

For #336351 (closed)

This is a bit of an odd fix.

There's a problem with the way the back end computes changes for the base display of an MR (something about HEAD versus BASE and squashed rebases).
Since that's a difficult problem to fix with a long timeline on a solution, this fix uses the correct value for the count of changed files (which comes from the "MR Metadata").

Once we have that number, the Vue app reaches back into the Rails-/HAML-rendered DOM and updates the tab's count badge.

A caveat

I'm not able to reproduce this issue using the steps in the linked issue OR on the MRs linked in that issue (that should be in a broken state).

However, a recent comment on the issue indicates that some people are still experiencing mis-counts.
Because this is a very general solution that isn't tied to any specific steps (e.g. you don't have to squash in order for this fix to take effect), I think it's still probably a good idea to go ahead with it.

Screenshots or screen recordings

As noted above, I can't replicate the issue.
What this means in practice is that the badge number on the Changes tab doesn't change visually when the Vue app loads.

How to set up and validate locally

As noted above, I can't replicate the actual problem in the linked issue.

However, there are 2 different things you can try in order to validate this:

  1. Follow the replication steps in the linked issue. It all worked properly for me, but maybe it will fail for you (and then you can switch to this branch and see it working).
  2. Edit views/projects/merge_requests/show.html.haml with some random number (I used 12345) instead of @diffs_count, then load an MR and switch to the Changes tab. It will update the number to match the correct count of files changed.

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 Phil Hughes

Merge request reports