diff --git a/.rubocop_todo/rspec/context_wording.yml b/.rubocop_todo/rspec/context_wording.yml
index 559a15dc5ad3fbe03a92d32c6f199928d459a690..cc67643b8a43558b5d422bf02c76aaaf44f88eb7 100644
--- a/.rubocop_todo/rspec/context_wording.yml
+++ b/.rubocop_todo/rspec/context_wording.yml
@@ -1893,7 +1893,6 @@ RSpec/ContextWording:
- 'spec/lib/api/entities/application_setting_spec.rb'
- 'spec/lib/api/entities/basic_project_details_spec.rb'
- 'spec/lib/api/entities/clusters/agent_authorization_spec.rb'
- - 'spec/lib/api/entities/merge_request_basic_spec.rb'
- 'spec/lib/api/entities/nuget/dependency_group_spec.rb'
- 'spec/lib/api/entities/user_spec.rb'
- 'spec/lib/api/every_api_endpoint_spec.rb'
diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb
index cc3df474bef85a03e9391e1adc23fdbcaba778bf..07cd6eb5070c8e038c978e42cbce28ed02e0e1b7 100644
--- a/app/graphql/types/merge_request_type.rb
+++ b/app/graphql/types/merge_request_type.rb
@@ -197,9 +197,9 @@ class MergeRequestType < BaseObject
field :security_auto_fix, GraphQL::Types::Boolean, null: true,
description: 'Indicates if the merge request is created by @GitLab-Security-Bot.'
field :squash, GraphQL::Types::Boolean, null: false,
- description: 'Indicates if squash on merge is enabled.'
+ description: 'Indicates if the merge request will be squashed when merge in the merge request. [Project settings](https://docs.gitlab.com/ee/user/project/merge_requests/squash_and_merge.html#configure-squash-options-for-a-project) may override this value. Use `squash_on_merge` instead.'
field :squash_on_merge, GraphQL::Types::Boolean, null: false, method: :squash_on_merge?,
- description: 'Indicates if squash on merge is enabled.'
+ description: 'Indicates if the merge request will be squashed when merged.'
field :timelogs, Types::TimelogType.connection_type, null: false,
description: 'Timelogs on the merge request.'
diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md
index 4e62d0bf5d37340d3cc9a6f84fe9d5147ee9c56e..6c099034b64dcaa1c08a9ad7a221ed2b242fcf44 100644
--- a/doc/api/graphql/reference/index.md
+++ b/doc/api/graphql/reference/index.md
@@ -13228,8 +13228,8 @@ Maven metadata.
| `sourceBranchProtected` | [`Boolean!`](#boolean) | Indicates if the source branch is protected. |
| `sourceProject` | [`Project`](#project) | Source project of the merge request. |
| `sourceProjectId` | [`Int`](#int) | ID of the merge request source project. |
-| `squash` | [`Boolean!`](#boolean) | Indicates if squash on merge is enabled. |
-| `squashOnMerge` | [`Boolean!`](#boolean) | Indicates if squash on merge is enabled. |
+| `squash` | [`Boolean!`](#boolean) | Indicates if the merge request will be squashed when merge in the merge request. [Project settings](https://docs.gitlab.com/ee/user/project/merge_requests/squash_and_merge.html#configure-squash-options-for-a-project) may override this value. Use `squash_on_merge` instead. |
+| `squashOnMerge` | [`Boolean!`](#boolean) | Indicates if the merge request will be squashed when merged. |
| `state` | [`MergeRequestState!`](#mergerequeststate) | State of the merge request. |
| `subscribed` | [`Boolean!`](#boolean) | Indicates if the currently logged in user is subscribed to this merge request. |
| `targetBranch` | [`String!`](#string) | Target branch of the merge request. |
diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md
index c6714459643f1eb74aa942704d6cfa3315ed5237..7a972f4990fa5867a33e0325cdfb40143f26448c 100644
--- a/doc/api/merge_requests.md
+++ b/doc/api/merge_requests.md
@@ -1109,7 +1109,8 @@ POST /projects/:id/merge_requests
| `allow_collaboration` | boolean | no | Allow commits from members who can merge to the target branch. |
| `allow_maintainer_to_push` | boolean | no | Alias of `allow_collaboration`. |
| `approvals_before_merge` **(PREMIUM)** | integer | no | Number of approvals required before this can be merged (see below). |
-| `squash` | boolean | no | Squash commits into a single commit when merging. |
+| `squash` | boolean | no | Indicates if the merge request will be squashed when merged in the merge request. [Project settings](../user/project/merge_requests/squash_and_merge.md#configure-squash-options-for-a-project) may override this value. Use `squash_on_merge` instead. |
+| `squash_on_merge` | boolean | no | Indicates if the merge request will be squashed when merged. |
If `approvals_before_merge` is not provided, it inherits the value from the target project. If provided, the following conditions must hold for it to take effect:
@@ -1276,7 +1277,8 @@ PUT /projects/:id/merge_requests/:merge_request_iid
| `description` | string | no | Description of MR. Limited to 1,048,576 characters. |
| `state_event` | string | no | New state (close/reopen). |
| `remove_source_branch` | boolean | no | Flag indicating if a merge request should remove the source branch when merging. |
-| `squash` | boolean | no | Squash commits into a single commit when merging. |
+| `squash` | boolean | no | Indicates if the merge request will be squashed when merged in the merge request. [Project settings](../user/project/merge_requests/squash_and_merge.md#configure-squash-options-for-a-project) may override this value. Use `squash_on_merge` instead. |
+| `squash_on_merge` | boolean | no | Indicates if the merge request will be squashed when merged. |
| `discussion_locked` | boolean | no | Flag indicating if the merge request's discussion is locked. If the discussion is locked only project members can add, edit or resolve comments. |
| `allow_collaboration` | boolean | no | Allow commits from members who can merge to the target branch. |
| `allow_maintainer_to_push` | boolean | no | Alias of `allow_collaboration`. |
diff --git a/lib/api/entities/merge_request_basic.rb b/lib/api/entities/merge_request_basic.rb
index 55d58166590ac4a9e6680ab41fbb6dfac9d397c3..a7bdff1d32af16f1c151161aab00f5bae3a64bec 100644
--- a/lib/api/entities/merge_request_basic.rb
+++ b/lib/api/entities/merge_request_basic.rb
@@ -90,6 +90,7 @@ class MergeRequestBasic < IssuableEntity
end
expose :squash
+ expose :squash_on_merge?, as: :squash_on_merge
expose :task_completion_status
expose :cannot_be_merged?, as: :has_conflicts
expose :mergeable_discussions_state?, as: :blocking_discussions_resolved
diff --git a/spec/lib/api/entities/merge_request_basic_spec.rb b/spec/lib/api/entities/merge_request_basic_spec.rb
index 40f259b86e2e3bb75a989228d4eceb7dbcd433a5..53dc31ddb5fb4c97c4b0bd781449b46d143ee467 100644
--- a/spec/lib/api/entities/merge_request_basic_spec.rb
+++ b/spec/lib/api/entities/merge_request_basic_spec.rb
@@ -4,11 +4,9 @@
RSpec.describe ::API::Entities::MergeRequestBasic do
let_it_be(:user) { create(:user) }
- let_it_be(:project) { create(:project, :public) }
let_it_be(:merge_request) { create(:merge_request) }
let_it_be(:labels) { create_list(:label, 3) }
let_it_be(:merge_requests) { create_list(:labeled_merge_request, 10, :unique_branches, labels: labels) }
-
let_it_be(:entity) { described_class.new(merge_request) }
# This mimics the behavior of the `Grape::Entity` serializer
@@ -16,7 +14,7 @@ def present(obj)
described_class.new(obj).presented
end
- subject { entity.as_json }
+ subject(:json) { entity.as_json }
it 'includes basic fields' do
is_expected.to include(
@@ -53,7 +51,7 @@ def present(obj)
end
end
- context 'reviewers' do
+ describe 'reviewers' do
before do
merge_request.reviewers = [user]
end
@@ -64,4 +62,26 @@ def present(obj)
expect(result['reviewers'][0]['username']).to eq user.username
end
end
+
+ describe 'squash' do
+ subject { json[:squash] }
+
+ before do
+ merge_request.target_project.project_setting.update!(squash_option: :never)
+ merge_request.update!(squash: true)
+ end
+
+ it { is_expected.to eq(true) }
+ end
+
+ describe 'squash_on_merge' do
+ subject { json[:squash_on_merge] }
+
+ before do
+ merge_request.target_project.project_setting.update!(squash_option: :never)
+ merge_request.update!(squash: true)
+ end
+
+ it { is_expected.to eq(false) }
+ end
end