Class: Slackistrano::DeploymentMessaging

Inherits:
Messaging::Base
  • Object
show all
Defined in:
lib/deployment_notifications/deployment_messaging.rb

Instance Method Summary collapse

Instance Method Details

#info_item(item, value) ⇒ Object



5
6
7
# File 'lib/deployment_notifications/deployment_messaging.rb', line 5

def info_item(item, value)
  "#{item} - _*#{value.to_s.gsub("\n", '')}*_"
end

#info_list(items) ⇒ Object



9
10
11
# File 'lib/deployment_notifications/deployment_messaging.rb', line 9

def info_list(items)
  items.join(" \n ")
end

#payload_for_failedObject

Slightly tweaked failed message. See api.slack.com/docs/message-formatting



97
98
99
100
101
# File 'lib/deployment_notifications/deployment_messaging.rb', line 97

def payload_for_failed
  payload = super
  payload[:text] = "OMG :fire: #{payload[:text]}"
  payload
end

#payload_for_startingObject



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
51
52
53
54
55
56
57
58
# File 'lib/deployment_notifications/deployment_messaging.rb', line 13

def payload_for_starting
  deployer_name = ENV['DEPLOYER_NAME'] || `git log -n 1 --format='%ae'`

  if ENV['DEPLOYMENT_IDENTIFIER']
    deployment_identifier = ENV['DEPLOYMENT_IDENTIFIER']
  else
    deployment_identifier = Time.now.strftime("%Y%m%d_%H%M%S")
    ENV['DEPLOYMENT_IDENTIFIER'] = deployment_identifier
  end

  {
    "blocks": [
      {
        "type": 'section',
        "text": {
          "type": 'mrkdwn',
          "text": 'Deployment _*Started*_ for _*Eportfolio*_ application :wave:'
        }
      },
      { "type": 'divider' },
      {
        "type": 'section',
        "text": {
          "type": 'mrkdwn',
          "text": '_Information related to this deployment_:'
        }
      },
      {
        "type": 'section',
        "text": {
          "type": 'mrkdwn',
          "text": info_list([
                              info_item('Deployer name', deployer_name),
                              info_item('Deployment identifier', deployment_identifier),
                              info_item('Env', ENV['ENV_NAME'] || stage),
                              info_item('Branch', ENV['BRANCH_NAME'] || branch),
                              info_item('Last commit by', ENV['LAST_COMMIT_AUTHOR'] || `git log -n 1 --format='%ae'`),
                              info_item('Commit time', ENV['LAST_COMMIT_TIME'] || `git show -s --format=%cd`),
                              info_item('Commit id', ENV['LAST_COMMIT_ID'] || `git rev-parse --short HEAD`),
                              info_item('Commit message', ENV['LAST_COMMIT_MESSAGE'] || `git show -s --format=%s`)
                            ])
        }
      }
    ]
  }
end

#payload_for_updatedObject

Fancy updated message. See api.slack.com/docs/message-attachments



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/deployment_notifications/deployment_messaging.rb', line 67

def payload_for_updated
  {
    attachments: [{
                    color: 'good',
                    title: "#{application} Deployed :boom::bangbang:",
                    fields: [{
                               title: 'Deployment Identifier',
                               value: ENV['DEPLOYMENT_IDENTIFIER'],
                               short: true
                             },{
                               title: 'Environment',
                               value: stage,
                               short: true
                             }, {
                               title: 'Branch',
                               value: branch,
                               short: true
                             }, {
                               title: 'Time',
                               value: elapsed_time,
                               short: true
                             }],
                    fallback: super[:text]
                  }],
    text: "<!here> #{application} Application Deployed!"
  }
end

#payload_for_updatingObject

Suppress updating message.



61
62
63
# File 'lib/deployment_notifications/deployment_messaging.rb', line 61

def payload_for_updating
  nil
end