Loading
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::MergeRequestMetricsServicestores them duringMergeRequests::PostMergeService, before themergehooks run. They staynullfor other actions. - The CE builder already loads
metricsandmerge_request_diff, so the payload needs no extra query. AQueryRecorderspec covers this. One edge case: whenfiles_countisnilor at the 2-byte sentinel (32767 files or more),MergeRequestDiff#files_countruns aCOUNT. - 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_countis in the CE builder. - Line counts and
file_countonly cover the files within the diff limits, so they are lower than the actual size for larger diffs. - The field is named
changed_linesrather thanchangesto avoid confusion with the top-levelchangesobject.
References
- Feature proposal: #638585
- Webhook development guidelines
Screenshots or screen recordings
object_attributes excerpt of a merge event, from a local GDK:
| Before | After |
|---|---|
"action": "merge", |
"added_lines": 3, |
How to set up and validate locally
- Start a local HTTP receiver that logs
POSTrequest bodies. - In a project, go to Settings > Webhooks, add a webhook to the receiver URL, and select Merge request events.
- Open a merge request. In the
openpayload,added_lines,deleted_lines, andchanged_linesarenull, andfile_countis set. - Merge the merge request. In the
mergepayload, all four fields are set andchanged_linesequalsadded_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.
Edited by Adrien Gooris