2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-19 03:22:09 -05:00
|
|
|
module Gitlab
|
2017-05-31 01:50:53 -04:00
|
|
|
module SlashCommands
|
2017-01-19 03:22:09 -05:00
|
|
|
module Presenters
|
2017-01-26 09:30:34 -05:00
|
|
|
class IssueSearch < Presenters::Base
|
2017-02-08 10:42:27 -05:00
|
|
|
include Presenters::IssueBase
|
2017-01-26 09:30:34 -05:00
|
|
|
|
2017-01-19 03:22:09 -05:00
|
|
|
def present
|
2019-11-29 10:06:43 -05:00
|
|
|
text = if resource.count >= 5
|
2017-01-19 03:22:09 -05:00
|
|
|
"Here are the first 5 issues I found:"
|
2019-11-29 10:06:43 -05:00
|
|
|
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
|
2019-11-29 10:06:43 -05:00
|
|
|
"Here are the #{resource.count} issues I found:"
|
2017-01-19 03:22:09 -05:00
|
|
|
end
|
2017-01-10 13:43:58 -05:00
|
|
|
|
2017-01-19 03:22:09 -05:00
|
|
|
ephemeral_response(text: text, attachments: attachments)
|
|
|
|
end
|
2017-01-10 13:43:58 -05:00
|
|
|
|
2017-01-19 03:22:09 -05:00
|
|
|
private
|
2017-01-10 13:43:58 -05:00
|
|
|
|
2017-01-19 03:22:09 -05:00
|
|
|
def attachments
|
2019-11-29 10:06:43 -05:00
|
|
|
resource.map do |issue|
|
2020-07-27 08:09:50 -04:00
|
|
|
url = "[#{issue.to_reference}](#{url_for([project, issue])})"
|
2017-01-10 13:43:58 -05:00
|
|
|
|
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-10 13:43:58 -05:00
|
|
|
|
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
|
2019-11-29 10:06:43 -05:00
|
|
|
@project ||= resource.first.project
|
2017-01-19 03:22:09 -05:00
|
|
|
end
|
|
|
|
end
|
2017-01-10 13:43:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|