diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-01-26 15:30:34 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-01-30 09:33:04 +0100 |
commit | 5ec214b0a5d9d3f0f0418a0e14ebf30b60a14a12 (patch) | |
tree | 18912233ab7e38d449670327394b5d555dfcd0b0 | |
parent | 4ce1a17c9767a80dfae0b47cee236d2a5d88918b (diff) | |
download | gitlab-ce-5ec214b0a5d9d3f0f0418a0e14ebf30b60a14a12.tar.gz |
Rename presenters for consitency
16 files changed, 51 insertions, 40 deletions
diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index 4e5031a8a26..e7baa20356c 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -3,7 +3,7 @@ module Gitlab class Command < BaseCommand COMMANDS = [ Gitlab::ChatCommands::IssueShow, - Gitlab::ChatCommands::IssueCreate, + Gitlab::ChatCommands::IssueNew, Gitlab::ChatCommands::IssueSearch, Gitlab::ChatCommands::Deploy, ].freeze diff --git a/lib/gitlab/chat_commands/issue_create.rb b/lib/gitlab/chat_commands/issue_new.rb index 3f3d7de8b2e..016054ecd46 100644 --- a/lib/gitlab/chat_commands/issue_create.rb +++ b/lib/gitlab/chat_commands/issue_new.rb @@ -1,6 +1,6 @@ module Gitlab module ChatCommands - class IssueCreate < IssueCommand + class IssueNew < IssueCommand def self.match(text) # we can not match \n with the dot by passing the m modifier as than # the title and description are not seperated @@ -21,10 +21,10 @@ module Gitlab issue = create_issue(title: title, description: description) - if issue.errors.any? - presenter(issue).display_errors - else + if issue.persisted? presenter(issue).present + else + presenter(issue).display_errors end end @@ -35,7 +35,7 @@ module Gitlab end def presenter(issue) - Gitlab::ChatCommands::Presenters::NewIssue.new(issue) + Gitlab::ChatCommands::Presenters::IssueNew.new(issue) end end end diff --git a/lib/gitlab/chat_commands/issue_search.rb b/lib/gitlab/chat_commands/issue_search.rb index e2d3a0f466a..3491b53093e 100644 --- a/lib/gitlab/chat_commands/issue_search.rb +++ b/lib/gitlab/chat_commands/issue_search.rb @@ -12,12 +12,10 @@ module Gitlab def execute(match) issues = collection.search(match[:query]).limit(QUERY_LIMIT) - if issues.none? - Presenters::Access.new(issues).not_found - elsif issues.one? - Presenters::ShowIssue.new(issues.first).present + if issues.present? + Presenters::IssueSearch.new(issues).present else - Presenters::ListIssues.new(issues).present + Presenters::Access.new(issues).not_found end end end diff --git a/lib/gitlab/chat_commands/issue_show.rb b/lib/gitlab/chat_commands/issue_show.rb index 9f3e1b9a64b..d6013f4d10c 100644 --- a/lib/gitlab/chat_commands/issue_show.rb +++ b/lib/gitlab/chat_commands/issue_show.rb @@ -13,7 +13,7 @@ module Gitlab issue = find_by_iid(match[:iid]) if issue - Gitlab::ChatCommands::Presenters::ShowIssue.new(issue).present + Gitlab::ChatCommands::Presenters::IssueShow.new(issue).present else Gitlab::ChatCommands::Presenters::Access.new.not_found end diff --git a/lib/gitlab/chat_commands/presenters/deploy.rb b/lib/gitlab/chat_commands/presenters/deploy.rb index b1cfaac15af..863d0bf99ca 100644 --- a/lib/gitlab/chat_commands/presenters/deploy.rb +++ b/lib/gitlab/chat_commands/presenters/deploy.rb @@ -15,14 +15,6 @@ module Gitlab def too_many_actions ephemeral_response(text: "Too many actions defined") end - - private - - def resource_url - polymorphic_url( - [ @resource.project.namespace.becomes(Namespace), @resource.project, @resource] - ) - end end end end diff --git a/lib/gitlab/chat_commands/presenters/help.rb b/lib/gitlab/chat_commands/presenters/help.rb index c7a67467b7e..39ad3249f5b 100644 --- a/lib/gitlab/chat_commands/presenters/help.rb +++ b/lib/gitlab/chat_commands/presenters/help.rb @@ -9,10 +9,10 @@ module Gitlab private def help_message(trigger) - if @resource.none? - "No commands available :thinking_face:" - else + if @resource.present? header_with_list("Available commands", full_commands(trigger)) + else + "No commands available :thinking_face:" end end diff --git a/lib/gitlab/chat_commands/presenters/issuable.rb b/lib/gitlab/chat_commands/presenters/issuable.rb index 2cb6b1525fc..dfb1c8f6616 100644 --- a/lib/gitlab/chat_commands/presenters/issuable.rb +++ b/lib/gitlab/chat_commands/presenters/issuable.rb @@ -1,9 +1,7 @@ module Gitlab module ChatCommands module Presenters - class Issuable < Presenters::Base - private - + module Issuable def color(issuable) issuable.open? ? '#38ae67' : '#d22852' end diff --git a/lib/gitlab/chat_commands/presenters/new_issue.rb b/lib/gitlab/chat_commands/presenters/issue_new.rb index c7c6febb56e..d26dd22b2a0 100644 --- a/lib/gitlab/chat_commands/presenters/new_issue.rb +++ b/lib/gitlab/chat_commands/presenters/issue_new.rb @@ -1,14 +1,16 @@ module Gitlab module ChatCommands module Presenters - class NewIssue < Presenters::Issuable + class IssueNew < Presenters::Base + include Presenters::Issuable + def present - in_channel_response(show_issue) + in_channel_response(new_issue) end private - def show_issue + def new_issue { attachments: [ { @@ -33,6 +35,10 @@ module Gitlab "I opened an issue on behalf on #{author_profile_link}: *#{@resource.to_reference}* from #{project.name_with_namespace}" end + def project_link + "[#{project.name_with_namespace}](#{url_for(project)})" + end + def author_profile_link "[#{author.to_reference}](#{url_for(author)})" end diff --git a/lib/gitlab/chat_commands/presenters/list_issues.rb b/lib/gitlab/chat_commands/presenters/issue_search.rb index 2458b9356b7..d58a6d6114a 100644 --- a/lib/gitlab/chat_commands/presenters/list_issues.rb +++ b/lib/gitlab/chat_commands/presenters/issue_search.rb @@ -1,7 +1,9 @@ module Gitlab module ChatCommands module Presenters - class ListIssues < Presenters::Issuable + class IssueSearch < Presenters::Base + include Presenters::Issuable + def present text = if @resource.count >= 5 "Here are the first 5 issues I found:" diff --git a/lib/gitlab/chat_commands/presenters/show_issue.rb b/lib/gitlab/chat_commands/presenters/issue_show.rb index e5644a4ad7e..2fc671f13a6 100644 --- a/lib/gitlab/chat_commands/presenters/show_issue.rb +++ b/lib/gitlab/chat_commands/presenters/issue_show.rb @@ -1,7 +1,9 @@ module Gitlab module ChatCommands module Presenters - class ShowIssue < Presenters::Issuable + class IssueShow < Presenters::Base + include Presenters::Issuable + def present in_channel_response(show_issue) end @@ -16,7 +18,7 @@ module Gitlab title_link: resource_url, author_name: author.name, author_icon: author.avatar_url, - fallback: "New issue #{@resource.to_reference}: #{@resource.title}", + fallback: "Issue #{@resource.to_reference}: #{@resource.title}", pretext: pretext, text: text, color: color(@resource), diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index 2e4f7705f86..33e450d7f0a 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -1,11 +1,7 @@ module Mattermost class Command < Client def create(params) -<<<<<<< HEAD response = session_post("/api/v3/teams/#{params[:team_id]}/commands/create", -======= - response = json_post("/api/v3/teams/#{params[:team_id]}/commands/create", ->>>>>>> Revert removing of some files body: params.to_json) response['token'] diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb index d8b2303555c..0acf40de1d3 100644 --- a/spec/lib/gitlab/chat_commands/command_spec.rb +++ b/spec/lib/gitlab/chat_commands/command_spec.rb @@ -94,7 +94,7 @@ describe Gitlab::ChatCommands::Command, service: true do context 'IssueCreate is triggered' do let(:params) { { text: 'issue create my title' } } - it { is_expected.to eq(Gitlab::ChatCommands::IssueCreate) } + it { is_expected.to eq(Gitlab::ChatCommands::IssueNew) } end context 'IssueSearch is triggered' do diff --git a/spec/lib/gitlab/chat_commands/issue_create_spec.rb b/spec/lib/gitlab/chat_commands/issue_new_spec.rb index 0f84b19a5a4..84c22328064 100644 --- a/spec/lib/gitlab/chat_commands/issue_create_spec.rb +++ b/spec/lib/gitlab/chat_commands/issue_new_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::ChatCommands::IssueCreate, service: true do +describe Gitlab::ChatCommands::IssueNew, service: true do describe '#execute' do let(:project) { create(:empty_project) } let(:user) { create(:user) } diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb new file mode 100644 index 00000000000..17fcdbc2452 --- /dev/null +++ b/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Gitlab::ChatCommands::Presenters::IssueNew do + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:attachment) { subject[:attachments].first } + + subject { described_class.new(issue).present } + + it { is_expected.to be_a(Hash) } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject).to have_key(:attachments) + expect(attachment[:title]).to start_with(issue.title) + end +end diff --git a/spec/lib/gitlab/chat_commands/presenters/list_issues_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb index 13a1f70fe78..ec6d3e34a96 100644 --- a/spec/lib/gitlab/chat_commands/presenters/list_issues_spec.rb +++ b/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::ChatCommands::Presenters::ListIssues do +describe Gitlab::ChatCommands::Presenters::IssueSearch do let(:project) { create(:empty_project) } let(:message) { subject[:text] } diff --git a/spec/lib/gitlab/chat_commands/presenters/show_issue_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb index ca4062e692a..89d154e26e4 100644 --- a/spec/lib/gitlab/chat_commands/presenters/show_issue_spec.rb +++ b/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::ChatCommands::Presenters::ShowIssue do +describe Gitlab::ChatCommands::Presenters::IssueShow do let(:project) { create(:empty_project) } let(:issue) { create(:issue, project: project) } let(:attachment) { subject[:attachments].first } |