incubator-devlake
incubator-devlake copied to clipboard
fix(gitlab): use diff_stats instead of changes_count for correct MR s…
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— addedDiffStatsstruct toMergeRequestResand mappedAdditions/DeletionsinconvertMergeRequestbackend/plugins/gitlab/models/mr.go— addedAdditionsandDeletionsfields toGitlabMergeRequestbackend/plugins/gitlab/tasks/shared.go— addedinclude_diff_stats=truequery param toGetQuerybackend/plugins/gitlab/models/migrationscripts/— added migration script and registered it
Fixes #8888