summaryrefslogtreecommitdiff
path: root/lib/gitlab/chat_commands/presenters/issue_new.rb
blob: a1a3add56c9ed1d675df2388d0cc1c19514e8190 (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
48
49
50
module Gitlab
  module ChatCommands
    module Presenters
      class IssueNew < Presenters::Base
        include Presenters::Issuable

        def present
          in_channel_response(new_issue)
        end

        private

        def new_issue 
          {
            attachments: [
              {
                title:        "#{@resource.title} ยท #{@resource.to_reference}",
                title_link:   resource_url,
                author_name:  author.name,
                author_icon:  author.avatar_url,
                fallback:     "New issue #{@resource.to_reference}: #{@resource.title}",
                pretext:      pretext,
                color:        color(@resource),
                fields:       fields,
                mrkdwn_in: [
                  :title,
                  :pretext,
                  :text,
                  :fields
                ]
              }
            ]
          }
        end

        def pretext
          "I created an issue on #{author_profile_link}'s behalf: **#{@resource.to_reference}** in #{project_link}"
        end

        def project_link
          "[#{project.name_with_namespace}](#{projects_url(project)})"
        end

        def author_profile_link
          "[#{author.to_reference}](#{url_for(author)})"
        end
      end
    end
  end
end