Commit 4501e458 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '323497-improve-error-when-command-is-unavailable' into 'master'

Show error when quick action is not available

See merge request gitlab-org/gitlab!57570
parents 9e2a2cec cdf3115a
---
title: Give better feedback when quick actions have no effect
merge_request: 57570
author: Hilco van der Wilk
type: fixed
......@@ -390,11 +390,11 @@ RSpec.describe QuickActions::InterpretService do
allow(current_user).to receive(:can?).with(:admin_issue, project).and_return(false)
end
it 'returns empty message' do
it 'returns an error message' do
_, updates, message = service.execute(content, issue)
expect(updates).to be_empty
expect(message).to be_empty
expect(message).to eq('Could not apply iteration command.')
end
end
end
......@@ -458,11 +458,11 @@ RSpec.describe QuickActions::InterpretService do
allow(current_user).to receive(:can?).with(:admin_issue, project).and_return(false)
end
it 'returns empty message' do
it 'returns an error message' do
_, updates, message = service.execute(content, issue)
expect(updates).to be_empty
expect(message).to be_empty
expect(message).to eq('Could not apply remove_iteration command.')
end
end
end
......
......@@ -56,15 +56,18 @@ module Gitlab
end
def execute(context, arg)
return unless executable?(context)
return if noop?
count_commands_executed_in(context)
return unless available?(context)
execute_block(action_block, context, arg)
end
def execute_message(context, arg)
return unless executable?(context)
return if noop?
return _('Could not apply %{name} command.') % { name: name } unless available?(context)
if execution_message.respond_to?(:call)
execute_block(execution_message, context, arg)
......@@ -101,10 +104,6 @@ module Gitlab
private
def executable?(context)
!noop? && available?(context)
end
def count_commands_executed_in(context)
return unless context.respond_to?(:commands_executed_count=)
......
......@@ -8645,6 +8645,9 @@ msgstr ""
msgid "Could not add admins as members"
msgstr ""
msgid "Could not apply %{name} command."
msgstr ""
msgid "Could not archive %{design}. Please try again."
msgstr ""
......
Return-Path: <jake@adventuretime.ooo>
Received: from iceking.adventuretime.ooo ([unix socket]) by iceking (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA; Thu, 13 Jun 2013 17:03:50 -0400
Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) by iceking.adventuretime.ooo (8.14.3/8.14.3/Debian-9.4) with ESMTP id r5DL3nFJ016967 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for <reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 17:03:50 -0400
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 14:03:48 -0700
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
Date: Thu, 13 Jun 2013 17:03:48 -0400
From: Jake the Dog <jake@adventuretime.ooo>
To: reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
In-Reply-To: <issue_1@localhost>
References: <reply-59d8df8370b7e95c5a49fbf86aeb2c93@localhost> <issue_1@localhost>
Subject: re: [Discourse Meta] eviltrout posted in 'Adventure Time Sux'
Mime-Version: 1.0
Content-Type: text/plain;
charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Sieve: CMU Sieve 2.2
X-Received: by 10.0.0.1 with SMTP id n7mr11234144ipb.85.1371157428600; Thu,
13 Jun 2013 14:03:48 -0700 (PDT)
X-Scanned-By: MIMEDefang 2.69 on IPv6:2001:470:1d:165::1
/close
......@@ -22,7 +22,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteOnIssuableHandler do
it_behaves_like :note_handler_shared_examples, true do
let_it_be(:recipient) { user }
let(:update_commands_only) { email_reply_fixture('emails/update_commands_only_reply.eml') }
let(:update_commands_only) { email_reply_fixture('emails/update_commands_only.eml') }
let(:no_content) { email_reply_fixture('emails/no_content_reply.eml') }
let(:commands_in_reply) { email_reply_fixture('emails/commands_in_reply.eml') }
let(:with_quick_actions) { email_reply_fixture('emails/valid_reply_with_quick_actions.eml') }
......
......@@ -127,10 +127,10 @@ RSpec.describe Gitlab::QuickActions::CommandDefinition do
subject.condition_block = proc { false }
end
it "doesn't execute the command" do
it "counts the command as executed" do
subject.execute(context, nil)
expect(context.commands_executed_count).to be_nil
expect(context.commands_executed_count).to eq(1)
expect(context.run).to be false
end
end
......@@ -238,8 +238,8 @@ RSpec.describe Gitlab::QuickActions::CommandDefinition do
subject.condition_block = proc { false }
end
it 'returns nil' do
expect(subject.execute_message({}, nil)).to be_nil
it 'returns an error message' do
expect(subject.execute_message({}, nil)).to eq('Could not apply command command.')
end
end
......
......@@ -345,6 +345,24 @@ RSpec.describe Notes::CreateService do
expect(note.errors[:commands_only]).to be_present
end
it 'adds commands failed message to note errors' do
note_text = %(/reopen)
note = described_class.new(project, user, opts.merge(note: note_text)).execute
expect(note.errors[:commands_only]).to contain_exactly('Could not apply reopen command.')
end
it 'generates success and failed error messages' do
note_text = %(/close\n/reopen)
service = double(:service)
allow(Issues::UpdateService).to receive(:new).and_return(service)
expect(service).to receive(:execute)
note = described_class.new(project, user, opts.merge(note: note_text)).execute
expect(note.errors[:commands_only]).to contain_exactly('Closed this issue. Could not apply reopen command.')
end
end
end
......
......@@ -82,8 +82,8 @@ RSpec.shared_examples :note_handler_shared_examples do |forwardable|
let!(:email_raw) { update_commands_only }
context 'and current user cannot update noteable' do
it 'raises a CommandsOnlyNoteError' do
expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidNoteError)
it 'does not raise an error' do
expect { receiver.execute }.not_to raise_error
end
end
......@@ -92,15 +92,11 @@ RSpec.shared_examples :note_handler_shared_examples do |forwardable|
project.add_developer(user)
end
it 'does not raise an error', unless: forwardable do
it 'does not raise an error' do
expect { receiver.execute }.to change { noteable.resource_state_events.count }.by(1)
expect(noteable.reload).to be_closed
end
it 'raises an InvalidNoteError', if: forwardable do
expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidNoteError)
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment