diff --git a/app/graphql/types/diff_type.rb b/app/graphql/types/diff_type.rb index 1c67c8c645a4595b181b8ce142953db7f255858d..5bedf605dfbf6eb6ce20e1f15eaff08b5ef69dc1 100644 --- a/app/graphql/types/diff_type.rb +++ b/app/graphql/types/diff_type.rb @@ -9,6 +9,9 @@ class DiffType < BaseObject description: 'Old file mode of the file.' field :b_mode, GraphQL::Types::String, null: true, description: 'New file mode of the file.' + field :collapsed, GraphQL::Types::String, null: true, + description: 'File diffs are excluded but can be fetched on request.', + method: :collapsed? field :deleted_file, GraphQL::Types::String, null: true, description: 'Indicates if the file has been removed. ' field :diff, GraphQL::Types::String, null: true, @@ -21,6 +24,9 @@ class DiffType < BaseObject description: 'Old path of the file.' field :renamed_file, GraphQL::Types::String, null: true, description: 'Indicates if the file has been renamed.' + field :too_large, GraphQL::Types::String, null: true, + description: 'File diffs are excluded and cannot be retrieved.', + method: :too_large? end # rubocop: enable Graphql/AuthorizeTypes end diff --git a/doc/api/commits.md b/doc/api/commits.md index 62ad1fe4ee50177f94763a01eb8421dd230aa2f9..946466f857fec941547657d4dca55996fa28d90e 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -639,6 +639,12 @@ dry run. ## Get commit diff +{{< history >}} + +- `collapsed` and `too_large` response attributes [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/199633) in GitLab 18.4. + +{{< /history >}} + Get the diff of a commit in a project. ```plaintext @@ -671,12 +677,30 @@ curl --header "PRIVATE-TOKEN: " \ --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/diff" ``` +If successful, returns [`200 OK`](rest/troubleshooting.md#status-codes) and the following +response attributes: + +| Attribute | Type | Description | +|----------------|---------|-------------| +| `a_mode` | string | Old file mode of the file. | +| `b_mode` | string | New file mode of the file. | +| `collapsed` | boolean | File diffs are excluded but can be fetched on request. | +| `deleted_file` | boolean | File has been removed. | +| `diff` | string | Diff representation of the changes made to the file. | +| `new_file` | boolean | File has been added. | +| `new_path` | string | New path of the file. | +| `old_path` | string | Old path of the file. | +| `renamed_file` | boolean | File has been renamed. | +| `too_large` | boolean | File diffs are excluded and cannot be retrieved. | + Example response: ```json [ { "diff": "@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files", + "collapsed": false, + "too_large": false, "new_path": "doc/update/5.4-to-6.0.md", "old_path": "doc/update/5.4-to-6.0.md", "a_mode": null, diff --git a/doc/api/graphql/reference/_index.md b/doc/api/graphql/reference/_index.md index 76d38d9a908d13342847bfe2270cf46ffe424087..8df88b8eaf86abf4dbde61385b6ca4fdfde6e158 100644 --- a/doc/api/graphql/reference/_index.md +++ b/doc/api/graphql/reference/_index.md @@ -28601,12 +28601,14 @@ Snapshot. | ---- | ---- | ----------- | | `aMode` | [`String`](#string) | Old file mode of the file. | | `bMode` | [`String`](#string) | New file mode of the file. | +| `collapsed` | [`String`](#string) | File diffs are excluded but can be fetched on request. | | `deletedFile` | [`String`](#string) | Indicates if the file has been removed. | | `diff` | [`String`](#string) | Diff representation of the changes made to the file. | | `newFile` | [`String`](#string) | Indicates if the file has just been added. | | `newPath` | [`String`](#string) | New path of the file. | | `oldPath` | [`String`](#string) | Old path of the file. | | `renamedFile` | [`String`](#string) | Indicates if the file has been renamed. | +| `tooLarge` | [`String`](#string) | File diffs are excluded and cannot be retrieved. | ### `DiffPosition` diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index d7689f4f0e24949e1edd15e9a9f2bfbfaceb23dc..5e47e25f3079969d48e6693c3e9863ee99ca2d33 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -1894,6 +1894,7 @@ Example response: - `generated_file` [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/141576) in GitLab 16.9 [with a flag](../administration/feature_flags/_index.md) named `collapse_generated_diff_files`. Disabled by default. - [Enabled on GitLab.com and GitLab Self-Managed](https://gitlab.com/gitlab-org/gitlab/-/issues/432670) in GitLab 16.10. - `generated_file` [generally available](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148478) in GitLab 16.11. Feature flag `collapse_generated_diff_files` removed. +- `collapsed` and `too_large` response attributes [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/199633) in GitLab 18.4. {{< /history >}} @@ -1916,17 +1917,19 @@ Supported attributes: If successful, returns [`200 OK`](rest/troubleshooting.md#status-codes) and the following response attributes: -| Attribute | Type | Description | -|----------------|---------|-------------| -| `old_path` | string | Old path of the file. | -| `new_path` | string | New path of the file. | -| `a_mode` | string | Old file mode of the file. | -| `b_mode` | string | New file mode of the file. | -| `diff` | string | Diff representation of the changes made to the file. | -| `new_file` | boolean | Indicates if the file has just been added. | -| `renamed_file` | boolean | Indicates if the file has been renamed. | -| `deleted_file` | boolean | Indicates if the file has been removed. | -| `generated_file` | boolean | Indicates if the file is [marked as generated](../user/project/merge_requests/changes.md#collapse-generated-files). [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/141576) in GitLab 16.9. | +| Attribute | Type | Description | +|------------------|---------|-------------| +| `a_mode` | string | Old file mode of the file. | +| `b_mode` | string | New file mode of the file. | +| `collapsed` | boolean | File diffs are excluded but can be fetched on request. | +| `deleted_file` | boolean | File has been removed. | +| `diff` | string | Diff representation of the changes made to the file. | +| `generated_file` | boolean | File is [marked as generated](../user/project/merge_requests/changes.md#collapse-generated-files). | +| `new_file` | boolean | File has been added. | +| `new_path` | string | New path of the file. | +| `old_path` | string | Old path of the file. | +| `renamed_file` | boolean | File has been renamed. | +| `too_large` | boolean | File diffs are excluded and cannot be retrieved. | Example request: @@ -1945,6 +1948,8 @@ Example response: "a_mode": "100644", "b_mode": "100644", "diff": "@@ -1 +1 @@\ -Title\ +README", + "collapsed": false, + "too_large": false, "new_file": false, "renamed_file": false, "deleted_file": false, @@ -1956,6 +1961,8 @@ Example response: "a_mode": "100644", "b_mode": "100644", "diff": "@@\ -1.9.7\ +1.9.8", + "collapsed": false, + "too_large": false, "new_file": false, "renamed_file": false, "deleted_file": false, @@ -3685,6 +3692,12 @@ Example response: ## Get a single merge request diff version +{{< history >}} + +- `collapsed` and `too_large` response attributes [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/199633) in GitLab 18.4. + +{{< /history >}} + Get a single merge request diff version. ```plaintext @@ -3725,15 +3738,17 @@ response attributes: | `commits[].web_url` | string | Web URL of the merge request. | | `created_at` | datetime | Creation date and time of the merge request. | | `diffs` | object array | Diffs in the merge request diff version. | +| `diffs[].a_mode` | string | Old file mode of the file. | +| `diffs[].b_mode` | string | New file mode of the file. | +| `diffs[].collapsed` | boolean | File diffs are excluded but can be fetched on request. | +| `diffs[].deleted_file` | boolean | File has been removed. | | `diffs[].diff` | string | Content of the diff. | +| `diffs[].generated_file` | boolean | File is [marked as generated](../user/project/merge_requests/changes.md#collapse-generated-files). | +| `diffs[].new_file` | boolean | File has been added. | | `diffs[].new_path` | string | New path of the file. | | `diffs[].old_path` | string | Old path of the file. | -| `diffs[].a_mode` | string | Old file mode of the file. | -| `diffs[].b_mode` | string | New file mode of the file. | -| `diffs[].new_file` | boolean | Indicates an added file. | -| `diffs[].renamed_file` | boolean | Indicates a renamed file. | -| `diffs[].deleted_file` | boolean | Indicates a removed file. | -| `diffs[].generated_file` | boolean | Indicates if the file is [marked as generated](../user/project/merge_requests/changes.md#collapse-generated-files). [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/141576) in GitLab 16.9. | +| `diffs[].renamed_file` | boolean | File has been renamed. | +| `diffs[].too_large` | boolean | File diffs are excluded and cannot be retrieved. | | `head_commit_sha` | string | HEAD commit of the source branch. | | `merge_request_id` | integer | ID of the merge request. | | `patch_id_sha` | string | [Patch ID](https://git-scm.com/docs/git-patch-id) for the merge request diff. | @@ -3816,6 +3831,8 @@ Example response: "a_mode": "0", "b_mode": "100644", "diff": "@@ -0,0 +1,21 @@\n+The MIT License (MIT)\n+\n+Copyright (c) 2018 Administrator\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in all\n+copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+SOFTWARE.\n", + "collapsed": false, + "too_large": false, "new_file": true, "renamed_file": false, "deleted_file": false, diff --git a/doc/api/openapi/openapi_v2.yaml b/doc/api/openapi/openapi_v2.yaml index 07de76c02fa1079455a6cb1be3c993ed1edb7018..3c2c409889551c8fef9b0997ae27a141b7e685c1 100644 --- a/doc/api/openapi/openapi_v2.yaml +++ b/doc/api/openapi/openapi_v2.yaml @@ -54511,6 +54511,10 @@ definitions: diff: type: string example: "@@ -71,6 +71,8 @@\\n..." + collapsed: + type: boolean + too_large: + type: boolean new_path: type: string example: doc/update/5.4-to-6.0.md diff --git a/doc/api/repositories.md b/doc/api/repositories.md index 9ed815d965e7703b8ca78972163ae5b59e3aa103..bd1365383166c6193919d993de17e800bd10660f 100644 --- a/doc/api/repositories.md +++ b/doc/api/repositories.md @@ -183,6 +183,12 @@ curl --header "PRIVATE-TOKEN: " \ ## Compare branches, tags or commits +{{< history >}} + +- `collapsed` and `too_large` response attributes [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/199633) in GitLab 18.4. + +{{< /history >}} + This endpoint can be accessed without authentication if the repository is publicly accessible. Diffs can have an empty diff string if diff limits are reached. @@ -202,6 +208,34 @@ Supported attributes: | `straight` | boolean | no | Comparison method: `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)'. Default is `false`. | | `unidiff` | boolean | No | Present diffs in the [unified diff](https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html) format. Default is false. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130610) in GitLab 16.5. | +If successful, returns [`200 OK`](rest/troubleshooting.md#status-codes) and the following +response attributes: + +| Attribute | Type | Description | +|-------------------------------|--------------|-------------| +| `commit` | object | Details of the latest commit in the comparison. | +| `commits` | object array | List of commits included in the comparison. | +| `commits[].author_email` | string | Commit author's email address. | +| `commits[].author_name` | string | Commit author's name. | +| `commits[].created_at` | datetime | Commit creation timestamp. | +| `commits[].id` | string | Full commit SHA. | +| `commits[].short_id` | string | Short commit SHA. | +| `commits[].title` | string | Commit title. | +| `compare_same_ref` | boolean | Comparison uses the same reference for both from and to. | +| `compare_timeout` | boolean | Comparison operation timed out. | +| `diffs` | object array | List of file differences. | +| `diffs[].a_mode` | string | Old file mode. | +| `diffs[].b_mode` | string | New file mode. | +| `diffs[].collapsed` | boolean | File diffs are excluded but can be fetched on request. | +| `diffs[].deleted_file` | boolean | File has been removed. | +| `diffs[].diff` | string | Diff content showing changes made to the file. | +| `diffs[].new_file` | boolean | File has been added. | +| `diffs[].new_path` | string | New path of the file. | +| `diffs[].old_path` | string | Old path of the file. | +| `diffs[].renamed_file` | boolean | File has been renamed. | +| `diffs[].too_large` | boolean | File diffs are excluded and cannot be retrieved. | +| `web_url` | string | Web URL for viewing the comparison. | + ```plaintext GET /projects/:id/repository/compare?from=main&to=feature ``` @@ -232,6 +266,8 @@ Example response: "a_mode": null, "b_mode": "100644", "diff": "@@ -24,8 +24,10 @@\n //= require g.raphael-min\n //= require g.bar-min\n //= require branch-graph\n-//= require highlightjs.min\n-//= require ace/ace\n //= require_tree .\n //= require d3\n //= require underscore\n+\n+function fix() { \n+ alert(\"Fixed\")\n+}", + "collapsed": false, + "too_large": false, "new_file": false, "renamed_file": false, "deleted_file": false diff --git a/lib/api/entities/diff.rb b/lib/api/entities/diff.rb index e1e6ce2626333e3ae32362216b6d057d22a7fcde..d533fd9ccadc155dc7f25fe8d6e8f7d33378678d 100644 --- a/lib/api/entities/diff.rb +++ b/lib/api/entities/diff.rb @@ -9,6 +9,8 @@ class Diff < Grape::Entity } do |instance, options| options[:enable_unidiff] == true ? instance.unidiff : instance.json_safe_diff end + expose :collapsed?, as: :collapsed, documentation: { type: 'boolean' } + expose :too_large?, as: :too_large, documentation: { type: 'boolean' } expose :new_path, documentation: { type: 'string', example: 'doc/update/5.4-to-6.0.md' } expose :old_path, documentation: { type: 'string', example: 'doc/update/5.4-to-6.0.md' } expose :a_mode, documentation: { type: 'string', example: '100755' } diff --git a/spec/graphql/types/diff_type_spec.rb b/spec/graphql/types/diff_type_spec.rb index 04f4ff9feeda1b4bd4349d4fb62664763d9156df..44d8b66b81bd4cd7e69d3ecc1c059f24ab6080d0 100644 --- a/spec/graphql/types/diff_type_spec.rb +++ b/spec/graphql/types/diff_type_spec.rb @@ -10,7 +10,7 @@ it 'contains attributes related to diff' do expect(described_class).to have_graphql_fields( - :a_mode, :b_mode, :deleted_file, :diff, :new_file, :new_path, :old_path, :renamed_file + :a_mode, :b_mode, :collapsed, :deleted_file, :diff, :new_file, :new_path, :old_path, :renamed_file, :too_large ) end diff --git a/spec/lib/api/entities/diff_spec.rb b/spec/lib/api/entities/diff_spec.rb index 535567d4d8dec2ffc9a5b2c71cd744923bf92a82..7e17ece7b0ad237e277d3b9b92aea113394caee5 100644 --- a/spec/lib/api/entities/diff_spec.rb +++ b/spec/lib/api/entities/diff_spec.rb @@ -17,6 +17,8 @@ expect(entity.as_json).to eq( { diff: diff.diff, + collapsed: diff.collapsed?, + too_large: diff.too_large?, new_path: diff.new_path, old_path: diff.old_path, a_mode: diff.a_mode,