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

46 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-01-19 03:22:09 -05:00
module Gitlab
module SlashCommands
2017-01-19 03:22:09 -05:00
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
2017-01-19 03:22:09 -05:00
"Here are the first 5 issues I found:"
elsif resource.one?
2017-01-30 06:12:57 -05:00
"Here is the only issue I found:"
2017-01-19 03:22:09 -05:00
else
"Here are the #{resource.count} issues I found:"
2017-01-19 03:22:09 -05:00
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([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
2017-01-19 03:22:09 -05:00
end
end
end
end
end