diff options
author | syasonik <syasonik@gitlab.com> | 2019-08-27 18:25:14 +0300 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-08-28 13:53:25 +0300 |
commit | a256b0056269f3504343c230971281d1873005f9 (patch) | |
tree | 2a6d0dbbfb63d4d8c5d4f045c30669b9bc63b6a2 | |
parent | ac3e7968fc9fdf9c4989602ba9bd6119aefcc945 (diff) | |
download | gitlab-ce-ce-slack-close-command.tar.gz |
Address already-closed issuesce-slack-close-command
-rw-r--r-- | lib/gitlab/slash_commands/issue_close.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/presenters/issue_close.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/slash_commands/issue_close_spec.rb | 10 |
3 files changed, 25 insertions, 8 deletions
diff --git a/lib/gitlab/slash_commands/issue_close.rb b/lib/gitlab/slash_commands/issue_close.rb index d28429018fc..5fcc86e91c4 100644 --- a/lib/gitlab/slash_commands/issue_close.rb +++ b/lib/gitlab/slash_commands/issue_close.rb @@ -18,13 +18,12 @@ module Gitlab def execute(match) issue = find_by_iid(match[:iid]) - if issue - close_issue(issue: issue) + return not_found unless issue + return presenter(issue).already_closed if issue.closed? - present(issue) - else - Gitlab::SlashCommands::Presenters::Access.new.not_found - end + close_issue(issue: issue) + + presenter(issue).present end private @@ -33,8 +32,12 @@ module Gitlab Issues::CloseService.new(project, current_user).execute(issue) end - def present(issue) - Gitlab::SlashCommands::Presenters::IssueClose.new(issue).present + def presenter(issue) + Gitlab::SlashCommands::Presenters::IssueClose.new(issue) + end + + def not_found + Gitlab::SlashCommands::Presenters::Access.new.not_found end end end diff --git a/lib/gitlab/slash_commands/presenters/issue_close.rb b/lib/gitlab/slash_commands/presenters/issue_close.rb index c817103a167..b3f24f4296a 100644 --- a/lib/gitlab/slash_commands/presenters/issue_close.rb +++ b/lib/gitlab/slash_commands/presenters/issue_close.rb @@ -14,6 +14,10 @@ module Gitlab end end + def already_closed + ephemeral_response(text: "Issue #{@resource.to_reference} is already closed.") + end + private def close_issue diff --git a/spec/lib/gitlab/slash_commands/issue_close_spec.rb b/spec/lib/gitlab/slash_commands/issue_close_spec.rb index 6e21a7cbc19..c0760ce0ba6 100644 --- a/spec/lib/gitlab/slash_commands/issue_close_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_close_spec.rb @@ -52,6 +52,16 @@ describe Gitlab::SlashCommands::IssueClose do expect(subject[:text]).to match("not found") end end + + context 'when the issue is already closed' do + let(:issue) { create(:issue, :closed, project: project) } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:ephemeral) + expect(issue.reload).to be_closed + expect(subject[:text]).to match("already closed") + end + end end describe '.match' do |