Add merge request size to merge request webhook payload

What does this MR do and why?

Adds the size of the merge request to object_attributes in the merge request webhook payload:

Field Value
added_lines merge_request_metrics.added_lines. null before merge. EE only.
deleted_lines merge_request_metrics.removed_lines. null before merge. EE only.
changed_lines added_lines + deleted_lines. null before merge. EE only.
file_count files_count of the latest merge request diff. 0 without a diff.

Receivers that store merge events for delivery analytics (for example in a data lake) need the size of merged changes. Today they must call the API for every merge event to get it.

  • The line counts already exist: EE::MergeRequestMetricsService stores them during MergeRequests::PostMergeService, before the merge hooks run. They stay null for other actions.
  • The CE builder already loads metrics and merge_request_diff, so the payload needs no extra query. A QueryRecorder spec covers this. One edge case: when files_count is nil or at the 2-byte sentinel (32767 files or more), MergeRequestDiff#files_count runs a COUNT.
  • The change is additive, so it is not a breaking payload change.
  • The line counts are in the EE builder because EE code computes them. file_count is in the CE builder.
  • Line counts and file_count only cover the files within the diff limits, so they are lower than the actual size for larger diffs.
  • The field is named changed_lines rather than changes to avoid confusion with the top-level changes object.

References

Screenshots or screen recordings

object_attributes excerpt of a merge event, from a local GDK:

Before After
"action": "merge",
"actioned_at": "..."
"added_lines": 3,
"deleted_lines": 1,
"changed_lines": 4,
"file_count": 1,
"action": "merge",
"actioned_at": "..."

How to set up and validate locally

  1. Start a local HTTP receiver that logs POST request bodies.
  2. In a project, go to Settings > Webhooks, add a webhook to the receiver URL, and select Merge request events.
  3. Open a merge request. In the open payload, added_lines, deleted_lines, and changed_lines are null, and file_count is set.
  4. Merge the merge request. In the merge payload, all four fields are set and changed_lines equals added_lines + deleted_lines.

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.

🤖 Generated with Claude Code

Edited by Adrien Gooris

Merge request reports

Loading
Loading