diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index dd392bd39a8fc04f016d841e3119bbb87e6f0165..1d9f81aaa23e3decdb6a1c4b2f1203d9271cc841 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -387,6 +387,7 @@ def project_params_attributes :merge_method, :initialize_with_readme, :autoclose_referenced_issues, + :suggestion_commit_message, project_feature_attributes: %i[ builds_access_level diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index 0bd2b0c81d9b56303874f0ac2cfcbcf2a8224427..31cde7b6d484f7adb092e573c619df6373f79d9e 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -104,6 +104,8 @@ class ProjectType < BaseObject description: 'Indicates if `Delete source branch` option should be enabled by default for all new merge requests of the project' field :autoclose_referenced_issues, GraphQL::BOOLEAN_TYPE, null: true, description: 'Indicates if issues referenced by merge requests and commits within the default branch are closed automatically' + field :suggestion_commit_message, GraphQL::STRING_TYPE, null: true, + description: 'The commit message used to apply merge request suggestions' field :namespace, Types::NamespaceType, null: true, description: 'Namespace of the project' diff --git a/app/services/suggestions/apply_service.rb b/app/services/suggestions/apply_service.rb index 8ba50e22b096f5f22050bd6217fe491a87307274..a6485e42bdb9f853cfcef744a2a6467872576cfa 100644 --- a/app/services/suggestions/apply_service.rb +++ b/app/services/suggestions/apply_service.rb @@ -2,6 +2,24 @@ module Suggestions class ApplyService < ::BaseService + DEFAULT_SUGGESTION_COMMIT_MESSAGE = 'Apply suggestion to %{file_path}' + + PLACEHOLDERS = { + 'project_path' => ->(suggestion, user) { suggestion.project.path }, + 'project_name' => ->(suggestion, user) { suggestion.project.name }, + 'file_path' => ->(suggestion, user) { suggestion.file_path }, + 'branch_name' => ->(suggestion, user) { suggestion.branch }, + 'username' => ->(suggestion, user) { user.username }, + 'user_full_name' => ->(suggestion, user) { user.name } + }.freeze + + # This regex is built dynamically using the keys from the PLACEHOLDER struct. + # So, we can easily add new placeholder just by modifying the PLACEHOLDER hash. + # This regex will build the new PLACEHOLDER_REGEX with the new information + PLACEHOLDERS_REGEX = Regexp.union(PLACEHOLDERS.keys.map { |key| Regexp.new(Regexp.escape(key)) }).freeze + + attr_reader :current_user + def initialize(current_user) @current_user = current_user end @@ -22,7 +40,7 @@ def execute(suggestion) end params = file_update_params(suggestion, diff_file) - result = ::Files::UpdateService.new(suggestion.project, @current_user, params).execute + result = ::Files::UpdateService.new(suggestion.project, current_user, params).execute if result[:status] == :success suggestion.update(commit_id: result[:result], applied: true) @@ -46,13 +64,14 @@ def latest_source_head?(suggestion) def file_update_params(suggestion, diff_file) blob = diff_file.new_blob + project = suggestion.project file_path = suggestion.file_path branch_name = suggestion.branch file_content = new_file_content(suggestion, blob) - commit_message = "Apply suggestion to #{file_path}" + commit_message = processed_suggestion_commit_message(suggestion) file_last_commit = - Gitlab::Git::Commit.last_for_path(suggestion.project.repository, + Gitlab::Git::Commit.last_for_path(project.repository, blob.commit_id, blob.path) @@ -75,5 +94,17 @@ def new_file_content(suggestion, blob) content.join end + + def suggestion_commit_message(project) + project.suggestion_commit_message || DEFAULT_SUGGESTION_COMMIT_MESSAGE + end + + def processed_suggestion_commit_message(suggestion) + message = suggestion_commit_message(suggestion.project) + + Gitlab::StringPlaceholderReplacer.replace_string_placeholders(message, PLACEHOLDERS_REGEX) do |key| + PLACEHOLDERS[key].call(suggestion, current_user) + end + end end end diff --git a/app/views/projects/_merge_request_merge_suggestions_settings.html.haml b/app/views/projects/_merge_request_merge_suggestions_settings.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..06bb9056e61540bb5da29b139638ffac577e4163 --- /dev/null +++ b/app/views/projects/_merge_request_merge_suggestions_settings.html.haml @@ -0,0 +1,17 @@ +- form = local_assigns.fetch(:form) + +.form-group + %b= s_('ProjectSettings|Merge suggestions') + %p.text-secondary + = s_('ProjectSettings|The commit message used to apply merge request suggestions') + = link_to icon('question-circle'), + help_page_path('user/discussions/index.md', + anchor: 'configure-the-commit-message-for-applied-suggestions'), + target: '_blank' + .mb-2 + = form.text_field :suggestion_commit_message, class: 'form-control mb-2', placeholder: Suggestions::ApplyService::DEFAULT_SUGGESTION_COMMIT_MESSAGE + %p.form-text.text-muted + = s_('ProjectSettings|The variables GitLab supports:') + - Suggestions::ApplyService::PLACEHOLDERS.keys.each do |placeholder| + %code + = "%{#{placeholder}}".html_safe diff --git a/app/views/projects/_merge_request_settings.html.haml b/app/views/projects/_merge_request_settings.html.haml index f2ba38387a32d8aaf85168bfbc374afa7db22a13..dc3a3fcc6473cc0c3f6aaf397eb2fe1834ed90de 100644 --- a/app/views/projects/_merge_request_settings.html.haml +++ b/app/views/projects/_merge_request_settings.html.haml @@ -5,3 +5,5 @@ = render 'projects/merge_request_merge_options_settings', project: @project, form: form = render 'projects/merge_request_merge_checks_settings', project: @project, form: form + += render 'projects/merge_request_merge_suggestions_settings', project: @project, form: form diff --git a/app/views/projects/_merge_request_settings_description_text.html.haml b/app/views/projects/_merge_request_settings_description_text.html.haml index 42964c900b3e8c7f58fc8145b457ed688225e1c2..dc9dc92675d5615e51776ac3f663a0b7824bd273 100644 --- a/app/views/projects/_merge_request_settings_description_text.html.haml +++ b/app/views/projects/_merge_request_settings_description_text.html.haml @@ -1 +1 @@ -%p= s_('ProjectSettings|Choose your merge method, merge options, and merge checks.') +%p= s_('ProjectSettings|Choose your merge method, merge options, merge checks, and merge suggestions.') diff --git a/changelogs/unreleased/feat-customizable-suggestion-commit-messages.yml b/changelogs/unreleased/feat-customizable-suggestion-commit-messages.yml new file mode 100644 index 0000000000000000000000000000000000000000..9fbff4118c8ef8a4ac820a25286b1d4e30562f6b --- /dev/null +++ b/changelogs/unreleased/feat-customizable-suggestion-commit-messages.yml @@ -0,0 +1,5 @@ +--- +title: Implement customizable commit messages for applied suggested changes +merge_request: 21411 +author: Fabio Huser +type: added diff --git a/db/migrate/20191208110214_add_suggestion_commit_message_to_projects.rb b/db/migrate/20191208110214_add_suggestion_commit_message_to_projects.rb new file mode 100644 index 0000000000000000000000000000000000000000..c4344cf212c39c26a01adf0400632047c79a3a92 --- /dev/null +++ b/db/migrate/20191208110214_add_suggestion_commit_message_to_projects.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddSuggestionCommitMessageToProjects < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def change + add_column :projects, :suggestion_commit_message, :string, limit: 255 + end +end diff --git a/db/schema.rb b/db/schema.rb index 97b2ffb2e762362c5f617404733ef1fbec1eaa46..819e78651da6cf4f5e91bb4c390b7e6e98c00c14 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -3347,6 +3347,7 @@ t.date "marked_for_deletion_at" t.integer "marked_for_deletion_by_user_id" t.boolean "autoclose_referenced_issues" + t.string "suggestion_commit_message", limit: 255 t.index "lower((name)::text)", name: "index_projects_on_lower_name" t.index ["created_at", "id"], name: "index_projects_on_created_at_and_id" t.index ["creator_id"], name: "index_projects_on_creator_id" diff --git a/doc/api/graphql/reference/gitlab_schema.graphql b/doc/api/graphql/reference/gitlab_schema.graphql index 345172658d2a418e93404396d8df6c9b551a393d..4c037a00857acc1dcddfbcb33e6499a4a15e1187 100644 --- a/doc/api/graphql/reference/gitlab_schema.graphql +++ b/doc/api/graphql/reference/gitlab_schema.graphql @@ -5154,6 +5154,11 @@ type Project { """ statistics: ProjectStatistics + """ + The commit message used to apply merge request suggestions + """ + suggestionCommitMessage: String + """ List of project tags """ diff --git a/doc/api/graphql/reference/gitlab_schema.json b/doc/api/graphql/reference/gitlab_schema.json index 2668ea98fc09b7be3484c7eb5765c248da1ec23a..eb6e3f8ef1682e0cd4bbf11bd537789525da0d69 100644 --- a/doc/api/graphql/reference/gitlab_schema.json +++ b/doc/api/graphql/reference/gitlab_schema.json @@ -1525,6 +1525,20 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "suggestionCommitMessage", + "description": "The commit message used to apply merge request suggestions", + "args": [ + + ], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "tagList", "description": "List of project tags", diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index 9e053c9cdcbe4d445e502f496be3fc6425ac5d56..2b8719f725dd5abbb4864e278b5e05a7e543b5c3 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -769,6 +769,7 @@ Information about pagination in a connection. | `printingMergeRequestLinkEnabled` | Boolean | Indicates if a link to create or view a merge request should display after a push to Git repositories of the project from the command line | | `removeSourceBranchAfterMerge` | Boolean | Indicates if `Delete source branch` option should be enabled by default for all new merge requests of the project | | `autocloseReferencedIssues` | Boolean | Indicates if issues referenced by merge requests and commits within the default branch are closed automatically | +| `suggestionCommitMessage` | String | The commit message used to apply merge request suggestions | | `namespace` | Namespace | Namespace of the project | | `group` | Group | Group of the project | | `statistics` | ProjectStatistics | Statistics of the project | diff --git a/doc/api/projects.md b/doc/api/projects.md index a856c01eb00fa205d053f3ae75c7043767c5f2da..8cfba68aceebe2dc1fd0390f22f3c78bf980cbc7 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -157,6 +157,7 @@ When the user is authenticated and `simple` is not set this returns something li "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 37, "storage_size": 1038090, @@ -256,6 +257,7 @@ When the user is authenticated and `simple` is not set this returns something li "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 12, "storage_size": 2066080, @@ -388,6 +390,7 @@ This endpoint supports [keyset pagination](README.md#keyset-based-pagination) fo "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 37, "storage_size": 1038090, @@ -487,6 +490,7 @@ This endpoint supports [keyset pagination](README.md#keyset-based-pagination) fo "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 12, "storage_size": 2066080, @@ -598,6 +602,7 @@ Example response: "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 37, "storage_size": 1038090, @@ -694,6 +699,7 @@ Example response: "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 12, "storage_size": 2066080, @@ -844,6 +850,7 @@ GET /projects/:id "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "statistics": { "commit_count": 37, "storage_size": 1038090, @@ -1068,6 +1075,7 @@ POST /projects/user/:user_id | `only_allow_merge_if_all_discussions_are_resolved` | boolean | no | Set whether merge requests can only be merged when all the discussions are resolved | | `merge_method` | string | no | Set the [merge method](#project-merge-method) used | | `autoclose_referenced_issues` | boolean | no | Set whether auto-closing referenced issues on default branch | +| `suggestion_commit_message` | string | no | The commit message used to apply merge request suggestions | | `remove_source_branch_after_merge` | boolean | no | Enable `Delete source branch` option by default for all new merge requests | | `lfs_enabled` | boolean | no | Enable LFS | | `request_access_enabled` | boolean | no | Allow users to request member access | @@ -1133,6 +1141,7 @@ PUT /projects/:id | `only_allow_merge_if_all_discussions_are_resolved` | boolean | no | Set whether merge requests can only be merged when all the discussions are resolved | | `merge_method` | string | no | Set the [merge method](#project-merge-method) used | | `autoclose_referenced_issues` | boolean | no | Set whether auto-closing referenced issues on default branch | +| `suggestion_commit_message` | string | no | The commit message used to apply merge request suggestions | | `remove_source_branch_after_merge` | boolean | no | Enable `Delete source branch` option by default for all new merge requests | | `lfs_enabled` | boolean | no | Enable LFS | | `request_access_enabled` | boolean | no | Allow users to request member access | @@ -1265,6 +1274,7 @@ Example responses: "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", @@ -1354,6 +1364,7 @@ Example response: "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", @@ -1442,6 +1453,7 @@ Example response: "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", @@ -1617,6 +1629,7 @@ Example response: "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", @@ -1724,6 +1737,7 @@ Example response: "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, + "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", diff --git a/doc/user/discussions/img/suggestion-commit-message-configuration.png b/doc/user/discussions/img/suggestion-commit-message-configuration.png new file mode 100644 index 0000000000000000000000000000000000000000..962bc9b0aeda3438cf3c4fce4be00f44e5bf5d57 Binary files /dev/null and b/doc/user/discussions/img/suggestion-commit-message-configuration.png differ diff --git a/doc/user/discussions/index.md b/doc/user/discussions/index.md index 56b4e94066553877e257fed40ae6dc35339f6cc4..0a2a9c6d2fa08e41af7c93911f89618949ab2856 100644 --- a/doc/user/discussions/index.md +++ b/doc/user/discussions/index.md @@ -414,9 +414,8 @@ the Merge Request authored by the user that applied them. Once the author applies a suggestion, it will be marked with the **Applied** label, the thread will be automatically resolved, and GitLab will create a new commit -with the message `Apply suggestion to ` and push the suggested change -directly into the codebase in the merge request's branch. -[Developer permission](../permissions.md) is required to do so. +and push the suggested change directly into the codebase in the merge request's +branch. [Developer permission](../permissions.md) is required to do so. > **Note:** Custom commit messages will be introduced by @@ -444,6 +443,24 @@ Suggestions covering multiple lines are limited to 100 lines _above_ and 100 lines _below_ the commented diff line, allowing up to 200 changed lines per suggestion. +### Configure the commit message for applied suggestions + +GitLab will use `Apply suggestion to %{file_path}` by default as commit messages +when applying change suggestions. This commit message can be customized to +follow any guidelines you might have. To do so, open the **Merge requests** tab +within your project settings and change the **Merge suggestions** text. + +![Suggestion Commit Message Configuration](img/suggestion-commit-message-configuration.png) + +You can also use following variables besides static text: + +- `%{project_path}`: The full URL safe project path. E.g: *my-group/my-project* +- `%{project_name}`: The human readable name of the project. E.g: *My Project* +- `%{file_path}`: The full path of the file the suggestion is applied to. E.g: *docs/index.md* +- `%{branch_name}`: The name of the branch the suggestion is applied on. E.g: *my-feature-branch* +- `%{username}`: The username of the user applying the suggestion. E.g: *user_1* +- `%{user_full_name}`: The full name of the user applying the suggestion. E.g: *User 1* + ## Start a thread by replying to a standard comment > [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/issues/30299) in GitLab 11.9 diff --git a/doc/user/project/settings/index.md b/doc/user/project/settings/index.md index f68ca90e2351c053b56041ad7ee8f9be715cbfc3..8fa005cc39cc57b450839d385b3ad9f2c0be822d 100644 --- a/doc/user/project/settings/index.md +++ b/doc/user/project/settings/index.md @@ -91,6 +91,7 @@ Set up your project's merge request settings: - Enable [merge only if pipeline succeeds](../merge_requests/merge_when_pipeline_succeeds.md). - Enable [merge only when all threads are resolved](../../discussions/index.md#only-allow-merge-requests-to-be-merged-if-all-threads-are-resolved). - Enable [`delete source branch after merge` option by default](../merge_requests/getting_started.md#deleting-the-source-branch) +- Configure [suggested changes commit messages](../../discussions/index.md#configure-the-commit-message-for-applied-suggestions) ![project's merge request settings](img/merge_requests_settings.png) diff --git a/ee/app/views/projects/_merge_request_settings.html.haml b/ee/app/views/projects/_merge_request_settings.html.haml index ec30239edf9028de6ae84623e3e8bd72c9f2a7c9..c989649267e944cf1f0cd6901eae0a62e18f6b68 100644 --- a/ee/app/views/projects/_merge_request_settings.html.haml +++ b/ee/app/views/projects/_merge_request_settings.html.haml @@ -6,6 +6,8 @@ = render_ce 'projects/merge_request_merge_checks_settings', project: @project, form: form += render 'projects/merge_request_merge_suggestions_settings', project: @project, form: form + - if @project.feature_available?(:issuable_default_templates) .form-group = form.label :merge_requests_template, class: 'label-bold' do diff --git a/ee/app/views/projects/_merge_request_settings_description_text.html.haml b/ee/app/views/projects/_merge_request_settings_description_text.html.haml index fc3b251f3b4f33fd56b2c7b153650edbabc12db3..2cbd3d6a615bb9c276248b77dd3ce072f40cde43 100644 --- a/ee/app/views/projects/_merge_request_settings_description_text.html.haml +++ b/ee/app/views/projects/_merge_request_settings_description_text.html.haml @@ -1,4 +1,4 @@ - if @project.feature_available?(:issuable_default_templates) - %p= s_('ProjectSettings|Choose your merge method, merge options, merge checks, and set up a default description template for merge requests.') + %p= s_('ProjectSettings|Choose your merge method, merge options, merge checks, merge suggestions, and set up a default description template for merge requests.') - else - %p= s_('ProjectSettings|Choose your merge method, merge options, and merge checks.') + %p= s_('ProjectSettings|Choose your merge method, merge options, merge checks, and merge suggestions.') diff --git a/ee/spec/features/projects/settings/merge_requests_settings_spec.rb b/ee/spec/features/projects/settings/merge_requests_settings_spec.rb index 85d59389b2e03c2cc0ccbe716d288ff5e6c7d5a1..7349d8a54ec438af8bb68b7baba7e82985741b5a 100644 --- a/ee/spec/features/projects/settings/merge_requests_settings_spec.rb +++ b/ee/spec/features/projects/settings/merge_requests_settings_spec.rb @@ -104,7 +104,7 @@ it "does not mention the merge request template in the section's description text" do visit edit_project_path(project) - expect(page).to have_content('Choose your merge method, merge options, and merge checks.') + expect(page).to have_content('Choose your merge method, merge options, merge checks, and merge suggestions.') end end @@ -122,7 +122,7 @@ it "mentions the merge request template in the section's description text" do visit edit_project_path(project) - expect(page).to have_content('Choose your merge method, merge options, merge checks, and set up a default description template for merge requests.') + expect(page).to have_content('Choose your merge method, merge options, merge checks, merge suggestions, and set up a default description template for merge requests.') end end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 9433edb20b0d03d9c0c1a4fe4c31340ebb896130..3cb438baa80f5255c02e1a7aa761b50632c95aff 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -335,6 +335,7 @@ class Project < BasicProjectDetails expose :remove_source_branch_after_merge expose :printing_merge_request_link_enabled expose :merge_method + expose :suggestion_commit_message expose :statistics, using: 'API::Entities::ProjectStatistics', if: -> (project, options) { options[:statistics] && Ability.allowed?(options[:current_user], :read_statistics, project) } diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index e4f943bd9251474ec6ffd4c4e566378c4b623b5f..6333e00daf5c72656264a436bbce72f12d9599ea 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -46,6 +46,7 @@ module ProjectsHelpers optional :avatar, type: File, desc: 'Avatar image for project' # rubocop:disable Scalability/FileUploads optional :printing_merge_request_link_enabled, type: Boolean, desc: 'Show link to create/view merge request when pushing from the command line' optional :merge_method, type: String, values: %w(ff rebase_merge merge), desc: 'The merge method used when merging merge requests' + optional :suggestion_commit_message, type: String, desc: 'The commit message used to apply merge request suggestions' optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md" optional :ci_default_git_depth, type: Integer, desc: 'Default number of revisions for shallow cloning' optional :auto_devops_enabled, type: Boolean, desc: 'Flag indication if Auto DevOps is enabled' @@ -119,6 +120,7 @@ def self.update_params_at_least_one_of :visibility, :wiki_access_level, :avatar, + :suggestion_commit_message, # TODO: remove in API v5, replaced by *_access_level :issues_enabled, diff --git a/locale/gitlab.pot b/locale/gitlab.pot index c0c905d5b2367b9de562553058637398e7425895..d581e605cb30406d31facc54f107ea4234deee2e 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -14124,10 +14124,10 @@ msgstr "" msgid "ProjectSettings|Build, test, and deploy your changes" msgstr "" -msgid "ProjectSettings|Choose your merge method, merge options, and merge checks." +msgid "ProjectSettings|Choose your merge method, merge options, merge checks, and merge suggestions." msgstr "" -msgid "ProjectSettings|Choose your merge method, merge options, merge checks, and set up a default description template for merge requests." +msgid "ProjectSettings|Choose your merge method, merge options, merge checks, merge suggestions, and set up a default description template for merge requests." msgstr "" msgid "ProjectSettings|Contact an admin to change this setting." @@ -14211,6 +14211,9 @@ msgstr "" msgid "ProjectSettings|Merge requests" msgstr "" +msgid "ProjectSettings|Merge suggestions" +msgstr "" + msgid "ProjectSettings|No merge commits are created" msgstr "" @@ -14262,6 +14265,12 @@ msgstr "" msgid "ProjectSettings|Submit changes to be merged upstream" msgstr "" +msgid "ProjectSettings|The commit message used to apply merge request suggestions" +msgstr "" + +msgid "ProjectSettings|The variables GitLab supports:" +msgstr "" + msgid "ProjectSettings|These checks must pass before merge requests can be merged" msgstr "" diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 27fa98bbde496b5b875aeaed4240fb97ca8b9b17..7bed1f72e0b068f6cc2458c9732799d84a890ac3 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -23,7 +23,7 @@ only_allow_merge_if_all_discussions_are_resolved printing_merge_request_link_enabled namespace group statistics repository merge_requests merge_request issues issue pipelines removeSourceBranchAfterMerge sentryDetailedError snippets - grafanaIntegration autocloseReferencedIssues + grafanaIntegration autocloseReferencedIssues suggestion_commit_message ] is_expected.to include_graphql_fields(*expected_fields) diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index adb49c8c7e7dcb85ae02c3cf7f5e87b1ecef1993..e5014eeca0951923a50c934be506c689e552b092 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -535,6 +535,7 @@ Project: - merge_requests_disable_committers_approval - require_password_to_approve - autoclose_referenced_issues +- suggestion_commit_message ProjectTracingSetting: - external_url Author: diff --git a/spec/services/suggestions/apply_service_spec.rb b/spec/services/suggestions/apply_service_spec.rb index bdbcb0fdb0748452d378d682da48505fb0c55879..84529af71877676be5400dcf78ea2884d4ece4b4 100644 --- a/spec/services/suggestions/apply_service_spec.rb +++ b/spec/services/suggestions/apply_service_spec.rb @@ -48,10 +48,34 @@ def apply(suggestion) expect(commit.committer_email).to eq(user.commit_email) expect(commit.author_name).to eq(user.name) end + + context 'when a custom suggestion commit message' do + before do + project.update!(suggestion_commit_message: message) + + apply(suggestion) + end + + context 'is not specified' do + let(:message) { nil } + + it 'sets default commit message' do + expect(project.repository.commit.message).to eq("Apply suggestion to files/ruby/popen.rb") + end + end + + context 'is specified' do + let(:message) { 'refactor: %{project_path} %{project_name} %{file_path} %{branch_name} %{username} %{user_full_name}' } + + it 'sets custom commit message' do + expect(project.repository.commit.message).to eq("refactor: project-1 Project_1 files/ruby/popen.rb master test.user Test User") + end + end + end end - let(:project) { create(:project, :repository) } - let(:user) { create(:user, :commit_email) } + let(:project) { create(:project, :repository, path: 'project-1', name: 'Project_1') } + let(:user) { create(:user, :commit_email, name: 'Test User', username: 'test.user') } let(:position) { build_position } @@ -113,7 +137,8 @@ def popen(cmd, path=nil) context 'non-fork project' do let(:merge_request) do create(:merge_request, source_project: project, - target_project: project) + target_project: project, + source_branch: 'master') end before do diff --git a/spec/views/projects/edit.html.haml_spec.rb b/spec/views/projects/edit.html.haml_spec.rb index 8005b5498384a43b2f919069ea1f2cabf3f5738d..e95dec56a2da2777e133933d475850c9508e7558 100644 --- a/spec/views/projects/edit.html.haml_spec.rb +++ b/spec/views/projects/edit.html.haml_spec.rb @@ -28,6 +28,33 @@ end end + context 'merge suggestions settings' do + it 'displays all possible variables' do + render + + expect(rendered).to have_content('%{project_path}') + expect(rendered).to have_content('%{project_name}') + expect(rendered).to have_content('%{file_path}') + expect(rendered).to have_content('%{branch_name}') + expect(rendered).to have_content('%{username}') + expect(rendered).to have_content('%{user_full_name}') + end + + it 'displays a placeholder if none is set' do + render + + expect(rendered).to have_field('project[suggestion_commit_message]', placeholder: 'Apply suggestion to %{file_path}') + end + + it 'displays the user entered value' do + project.update!(suggestion_commit_message: 'refactor: changed %{file_path}') + + render + + expect(rendered).to have_field('project[suggestion_commit_message]', with: 'refactor: changed %{file_path}') + end + end + context 'forking' do before do assign(:project, project)