diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/quick_actions | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/gitlab/quick_actions')
-rw-r--r-- | lib/gitlab/quick_actions/command_definition.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/quick_actions/issue_actions.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/quick_actions/merge_request_actions.rb | 77 |
3 files changed, 93 insertions, 6 deletions
diff --git a/lib/gitlab/quick_actions/command_definition.rb b/lib/gitlab/quick_actions/command_definition.rb index 8ce13db4c03..fcb7bc967ca 100644 --- a/lib/gitlab/quick_actions/command_definition.rb +++ b/lib/gitlab/quick_actions/command_definition.rb @@ -3,6 +3,8 @@ module Gitlab module QuickActions class CommandDefinition + ParseError = Class.new(StandardError) + attr_accessor :name, :aliases, :description, :explanation, :execution_message, :params, :condition_block, :parse_params_block, :action_block, :warning, :icon, :types @@ -41,7 +43,11 @@ module Gitlab return unless available?(context) message = if explanation.respond_to?(:call) - execute_block(explanation, context, arg) + begin + execute_block(explanation, context, arg) + rescue ParseError => e + format(_('Problem with %{name} command: %{message}.'), name: name, message: e.message) + end else explanation end @@ -63,6 +69,8 @@ module Gitlab return unless available?(context) execute_block(action_block, context, arg) + rescue ParseError + # message propagation is handled in `execution_message`. end def execute_message(context, arg) @@ -74,6 +82,8 @@ module Gitlab else execution_message end + rescue ParseError => e + format _('Could not apply %{name} command. %{message}.'), name: name, message: e.message end def to_h(context) diff --git a/lib/gitlab/quick_actions/issue_actions.rb b/lib/gitlab/quick_actions/issue_actions.rb index 5fd422db722..b44b47eca37 100644 --- a/lib/gitlab/quick_actions/issue_actions.rb +++ b/lib/gitlab/quick_actions/issue_actions.rb @@ -287,10 +287,11 @@ module Gitlab desc _('Add customer relation contacts') explanation _('Add customer relation contact(s).') - params 'contact@example.com person@example.org' + params '[contact:contact@example.com] [contact:person@example.org]' types Issue condition do - current_user.can?(:set_issue_crm_contacts, quick_action_target) + current_user.can?(:set_issue_crm_contacts, quick_action_target) && + CustomerRelations::Contact.exists_for_group?(quick_action_target.project.group) end execution_message do _('One or more contacts were successfully added.') @@ -301,10 +302,11 @@ module Gitlab desc _('Remove customer relation contacts') explanation _('Remove customer relation contact(s).') - params 'contact@example.com person@example.org' + params '[contact:contact@example.com] [contact:person@example.org]' types Issue condition do - current_user.can?(:set_issue_crm_contacts, quick_action_target) + current_user.can?(:set_issue_crm_contacts, quick_action_target) && + CustomerRelations::Contact.exists_for_group?(quick_action_target.project.group) end execution_message do _('One or more contacts were successfully removed.') diff --git a/lib/gitlab/quick_actions/merge_request_actions.rb b/lib/gitlab/quick_actions/merge_request_actions.rb index cc2021e14e3..842d4ef482b 100644 --- a/lib/gitlab/quick_actions/merge_request_actions.rb +++ b/lib/gitlab/quick_actions/merge_request_actions.rb @@ -57,6 +57,11 @@ module Gitlab access_check.can_push_to_branch?(merge_request.source_branch) end command :rebase do + unless quick_action_target.permits_force_push? + @execution_message[:rebase] = _('This merge request branch is protected from force push.') + next + end + if quick_action_target.cannot_be_merged? @execution_message[:rebase] = _('This merge request cannot be rebased while there are conflicts.') next @@ -184,7 +189,7 @@ module Gitlab execution_message do |users = nil| reviewers = reviewers_to_add(users) if reviewers.blank? - _("Failed to assign a reviewer because no user was found.") + _("Failed to assign a reviewer because no user was specified.") else _('Assigned %{reviewer_users_sentence} as %{reviewer_text}.') % { reviewer_users_sentence: reviewer_users_sentence(users), reviewer_text: 'reviewer'.pluralize(reviewers.size) } @@ -249,6 +254,76 @@ module Gitlab @updates[:reviewer_ids] = [] end end + + desc do + if quick_action_target.allows_multiple_reviewers? + _('Request attention from assignee(s) or reviewer(s)') + else + _('Request attention from assignee or reviewer') + end + end + explanation do |users| + _('Request attention from %{users_sentence}.') % { users_sentence: reviewer_users_sentence(users) } + end + execution_message do |users = nil| + if users.blank? + _("Failed to request attention because no user was found.") + else + _('Requested attention from %{users_sentence}.') % { users_sentence: reviewer_users_sentence(users) } + end + end + params do + quick_action_target.allows_multiple_reviewers? ? '@user1 @user2' : '@user' + end + types MergeRequest + condition do + Feature.enabled?(:mr_attention_requests, project, default_enabled: :yaml) && + current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project) + end + parse_params do |attention_param| + extract_users(attention_param) + end + command :attention do |users| + next if users.empty? + + users.each do |user| + ::MergeRequests::ToggleAttentionRequestedService.new(project: quick_action_target.project, merge_request: quick_action_target, current_user: current_user, user: user).execute + end + end + + desc do + if quick_action_target.allows_multiple_reviewers? + _('Remove attention request(s)') + else + _('Remove attention request') + end + end + explanation do |users| + _('Removes attention from %{users_sentence}.') % { users_sentence: reviewer_users_sentence(users) } + end + execution_message do |users = nil| + if users.blank? + _("Failed to remove attention because no user was found.") + else + _('Removed attention from %{users_sentence}.') % { users_sentence: reviewer_users_sentence(users) } + end + end + params do + quick_action_target.allows_multiple_reviewers? ? '@user1 @user2' : '@user' + end + types MergeRequest + condition do + Feature.enabled?(:mr_attention_requests, project, default_enabled: :yaml) && + current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project) + end + parse_params do |attention_param| + extract_users(attention_param) + end + command :remove_attention do |users| + next if users.empty? + + ::MergeRequests::BulkRemoveAttentionRequestedService.new(project: quick_action_target.project, merge_request: quick_action_target, current_user: current_user, users: users).execute + end end def reviewer_users_sentence(users) |