Add `raw_diff` option to list merge request diffs API

What does this MR do and why?

This merge request adds a new API endpoint to show raw diffs of files changed in a merge request. The endpoint introduced is: /projects/:id/merge_requests/:merge_request_iid/raw_diffs

and will show a response like:

diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md
index 5dc74f4d3667252166006688f840d66373ce99c2..12dafa2d2ed4cf9337265ee5dfbeb7bfe40c1252 100644
--- a/doc/api/merge_requests.md
+++ b/doc/api/merge_requests.md
@@ -1955,6 +1955,67 @@ NOTE:
 This endpoint is subject to [Merge requests diff limits](../administration/instance_limits.md#diff-limits).
 Merge requests that exceed the diff limits return limited results.
 
+## Show merge request raw diffs
+
+Show raw diffs of the files changed in a merge request.
+
+```plaintext
+GET /projects/:id/merge_requests/:merge_request_iid/raw_diffs
+```
+
+Supported attributes:
+
+| Attribute           | Type              | Required | Description |
+|---------------------|-------------------|----------|-------------|
+| `id`                | integer or string | Yes      | The ID or [URL-encoded path of the project](rest/index.md#namespaced-paths). |
+| `merge_request_iid` | integer           | Yes      | The internal ID of the merge request. |
+
+If successful, returns [`200 OK`](rest/troubleshooting.md#status-codes) and a raw diff response to use programatically:
+
+Example request:
+
+```shell
+curl --header "PRIVATE-TOKEN: <your_access_token>" \
+  --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/raw_diffs"
+```
+
+Example response:
+
+```diff
+        diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
+index 31525ad523553c8d7eff163db3e539058efd6d3a..f30e36d6fdf4cd4fa25f62e08ecdbf4a7b169681 100644

Similar to appending .diff to a merge request URL!

References

Add `raw` option to list merge request diffs API (#270960 - closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

In your local GDK instance:

  • Find a project that has a merge request with 1 or more changes
  • Get the project ID from the top right button
  • Get the IID of aforementioned merge request
  • Run a curl command such as:

curl "https://gdk.test:3443/api/v4/projects/3/merge_requests/7/raw_diffs" -H 'PRIVATE-TOKEN: supercooltoken'

Related to #270960 (closed)

Edited by Gary Holtz

Merge request reports

Loading