BigW Consortium Gitlab

issue_new.rb 1.29 KB
Newer Older
Z.J. van de Weg committed
1 2 3
module Gitlab
  module ChatCommands
    module Presenters
4
      class IssueNew < Presenters::Base
5
        include Presenters::IssueBase
6

Z.J. van de Weg committed
7
        def present
8
          in_channel_response(new_issue)
Z.J. van de Weg committed
9 10 11 12
        end

        private

13
        def new_issue
Z.J. van de Weg committed
14 15 16 17 18 19 20 21 22 23 24 25 26
          {
            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,
Z.J. van de Weg committed
27 28 29
                  :pretext,
                  :text,
                  :fields
Z.J. van de Weg committed
30 31 32 33 34 35 36
                ]
              }
            ]
          }
        end

        def pretext
37
          "I created an issue on #{author_profile_link}'s behalf: **#{@resource.to_reference}** in #{project_link}"
Z.J. van de Weg committed
38 39
        end

40
        def project_link
41
          "[#{project.name_with_namespace}](#{project.web_url})"
42 43
        end

Z.J. van de Weg committed
44 45 46 47 48 49 50
        def author_profile_link
          "[#{author.to_reference}](#{url_for(author)})"
        end
      end
    end
  end
end