incubator-devlake icon indicating copy to clipboard operation
incubator-devlake copied to clipboard

fix(gitlab): use diff_stats instead of changes_count for correct MR s…

Open bujjibabukatta opened this issue 5 months ago • 0 comments

Problem

GitLab MR size is incorrectly inflated when a branch has multiple sequential PRs. The changes_count field from GitLab's API returns cumulative line changes across all commits on the branch including previous PRs, not just the current MR's diff.

Root Cause

GitLab's changes_count sums all commits on the source branch. For multi-part PRs this means PR #3 shows 9292 lines changed instead of the actual 6523 lines in that PR alone.

Fix

Use GitLab's diff_stats field (via include_diff_stats=true query param) which returns additions/deletions relative to the merge base — only what this PR itself introduces.

Changes

  • backend/plugins/gitlab/tasks/mr_extractor.go — added DiffStats struct to MergeRequestRes and mapped Additions/Deletions in convertMergeRequest
  • backend/plugins/gitlab/models/mr.go — added Additions and Deletions fields to GitlabMergeRequest
  • backend/plugins/gitlab/tasks/shared.go — added include_diff_stats=true query param to GetQuery
  • backend/plugins/gitlab/models/migrationscripts/ — added migration script and registered it

Fixes #8888

bujjibabukatta avatar Jun 15 '26 11:06 bujjibabukatta