gitlab-org--gitlab-foss/lib/gitlab/chat_commands/presenters/issue_search.rb

48 lines
1.2 KiB
Ruby
Raw Normal View History

2017-01-19 03:22:09 -05:00
module Gitlab
module ChatCommands
module Presenters
2017-01-26 09:30:34 -05:00
class IssueSearch < Presenters::Base
include Presenters::IssueBase
2017-01-26 09:30:34 -05:00
2017-01-19 03:22:09 -05:00
def present
text = if @resource.count >= 5
"Here are the first 5 issues I found:"
2017-01-30 06:12:57 -05:00
elsif @resource.one?
"Here is the only issue I found:"
2017-01-19 03:22:09 -05:00
else
"Here are the #{@resource.count} issues I found:"
end
2017-01-19 03:22:09 -05:00
ephemeral_response(text: text, attachments: attachments)
end
2017-01-19 03:22:09 -05:00
private
2017-01-19 03:22:09 -05:00
def attachments
@resource.map do |issue|
url = "[#{issue.to_reference}](#{url_for([namespace, project, issue])})"
2017-01-19 03:22:09 -05:00
{
color: color(issue),
fallback: "#{issue.to_reference} #{issue.title}",
text: "#{url} · #{issue.title} (#{status_text(issue)})",
2017-01-19 03:22:09 -05:00
mrkdwn_in: [
2017-01-30 06:12:57 -05:00
:text
2017-01-19 03:22:09 -05:00
]
}
end
end
def project
@project ||= @resource.first.project
end
def namespace
@namespace ||= project.namespace.becomes(Namespace)
end
end
end
end
end