debian-mirror-gitlab/lib/gitlab/slash_commands/presenters/issue_search.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
2017-09-10 17:25:29 +05:30
module SlashCommands
2017-08-17 22:00:37 +05:30
module Presenters
class IssueSearch < Presenters::Base
include Presenters::IssueBase
def present
2020-01-01 13:55:28 +05:30
text = if resource.count >= 5
2017-08-17 22:00:37 +05:30
"Here are the first 5 issues I found:"
2020-01-01 13:55:28 +05:30
elsif resource.one?
2017-08-17 22:00:37 +05:30
"Here is the only issue I found:"
else
2020-01-01 13:55:28 +05:30
"Here are the #{resource.count} issues I found:"
2017-08-17 22:00:37 +05:30
end
ephemeral_response(text: text, attachments: attachments)
end
private
def attachments
2020-01-01 13:55:28 +05:30
resource.map do |issue|
2017-08-17 22:00:37 +05:30
url = "[#{issue.to_reference}](#{url_for([namespace, project, issue])})"
{
color: color(issue),
fallback: "#{issue.to_reference} #{issue.title}",
text: "#{url} · #{issue.title} (#{status_text(issue)})",
mrkdwn_in: [
:text
]
}
end
end
def project
2020-01-01 13:55:28 +05:30
@project ||= resource.first.project
2017-08-17 22:00:37 +05:30
end
def namespace
@namespace ||= project.namespace.becomes(Namespace)
end
end
end
end
end