Add diff_stats to merge request webhook payload

What does this MR do and why?

Add diff_stats to the merge request webhook payload. Currently, the MR webhook payload has no information about which files changed or how many lines were added or deleted. This makes it impossible for webhook consumers to act on code changes without making additional API calls.

This MR adds a diff_stats field to object_attributes containing:

  • A summary (additions, deletions, file_count)
  • A per-file breakdown (old_path, path, additions, deletions)

The field is only computed for events where the diff is relevant: open, merge, and update with actual code changes (oldrev present). It is omitted for events like label changes, approvals, and reviewer assignments where the diff has not changed.

The change is gated behind the mr_webhook_diff_stats feature flag (disabled by default).

References

  • Feature issue: Relates to #593438

Screenshots or screen recordings

N/A — backend change only, no UI impact.

How to set up and validate locally

Prerequisites: A running GDK instance.

  1. Enable the feature flag in the Rails console (gdk rails console):

    Feature.enable(:mr_webhook_diff_stats)
  2. Create a project with a README (check "Initialize repository with a README") or use an existing test project.

  3. Add a webhook to the project:

    • Go to Settings → Webhooks → Add new webhook
    • URL: http://example.com/webhook (delivery will fail, but the payload is still recorded)
    • Check Merge request events
    • Under Admin → Settings → Network → Outbound requests, enable "Allow requests to the local network from webhooks and integrations" if using a local URL
  4. Test: Open an MR

    • Clone the project, create a branch, add/modify a file, push, and open an MR
    • Go to Settings → Webhooks → Edit → Recent events
    • Verify object_attributes.diff_stats is present with additions, deletions, file_count, and a files array containing old_path, path, additions, deletions per file
  5. Test: Push a commit to the MR

    • Push another commit to the source branch
    • Verify diff_stats is present in the webhook payload (update with code change)
  6. Test: Add a label

    • Add a label to the MR
    • Verify diff_stats is not present in the payload (no code change)
  7. Test: Merge the MR

    • Merge the MR
    • Verify diff_stats is present in the payload
  8. Test: Feature flag disabled

    • Disable the flag: Feature.disable(:mr_webhook_diff_stats)
    • Open a new MR
    • Verify diff_stats is not present in the payload

Screenshot 2026-03-18 at 3.57.53 PM.png

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 Lohit Peesapati

Merge request reports

Loading