Welcome to mirror list, hosted at ThFree Co, Russian Federation.

issue_search.rb « presenters « chat_commands « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3478359b91d07c595b493bf0a8a9d53dcf659626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Gitlab
  module ChatCommands
    module Presenters
      class IssueSearch < Presenters::Base
        include Presenters::Issuable

        def present
          text = if @resource.count >= 5
                   "Here are the first 5 issues I found:"
                 elsif @resource.one?
                   "Here is the only issue I found:"
                 else
                   "Here are the #{@resource.count} issues I found:"
                 end

          ephemeral_response(text: text, attachments: attachments)
        end

        private

        def attachments
          @resource.map do |issue|
            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
          @project ||= @resource.first.project
        end

        def namespace
          @namespace ||= project.namespace.becomes(Namespace)
        end
      end
    end
  end
end