Class: Capistrano::Wearerequired::SlackistranoExpandedGitMessaging

Inherits:
SlackistranoMessagingColors show all
Defined in:
lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb

Instance Method Summary collapse

Methods inherited from SlackistranoMessagingColors

#payload_for_failed, #payload_for_reverted

Methods inherited from SlackistranoMessagingElements

#deployer, #initialize

Constructor Details

This class inherits a constructor from Capistrano::Wearerequired::SlackistranoMessagingElements

Instance Method Details

#author_iconObject



65
66
67
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 65

def author_icon
  "https://required.com/content/themes/required-valencia/assets/img/character-%{name}-300x300.png" % { name: deployer.downcase }
end


69
70
71
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 69

def author_link
  "https://required.com/team/%{name}/" % { name: deployer.downcase }
end

#current_revisionObject

Get current revision



16
17
18
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 16

def current_revision
  fetch(:current_revision)
end

#current_revision_urlObject

Get current revision URL



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 40

def current_revision_url
  "<https://%{host}/%{owner}/%{repo}/%{commit}/%{revision}|%{revision_short}@%{branch}>" % {
    :host => repo[:host],
    :owner => repo[:owner],
    :repo => repo[:repo],
    :commit => 'bitbucket.org' == repo[:host] ? 'commits' : 'commit',
    :revision => current_revision,
    :revision_short => current_revision[0..10],
    :branch => branch
  }
end


85
86
87
88
89
90
91
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 85

def footer
  if repo.nil? || current_revision.nil? || previous_revision.nil?
    ''
  else
    'Diff: ' + revision_compare_url
  end
end


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 73

def footer_icon
  if repo.nil?
   ''
  elsif 'bitbucket.org' == repo[:host]
    'https://bitbucket.org/site/master/avatar/64/'
  elsif 'gitlab.com' == repo[:host]
    'https://gitlab.com/uploads/system/project/avatar/13083/logo-extra-whitespace.png'
  elsif 'github.com' == repo[:host]
    'https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png'
  end
end

#payload_for_revertingObject

Suppress reverting message.



11
12
13
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 11

def payload_for_reverting
  nil
end

#payload_for_updatedObject

More detailed updated message.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 94

def payload_for_updated
{
  attachments: [{
    color: 'good',
    pretext: application + ' was successfully deployed :white_check_mark:',
    author_name: deployer.capitalize,
    author_icon: author_icon,
    author_link: author_link,
    footer: footer,
    footer_icon: footer_icon,
    fields: [{
      title: 'Environment',
      value: stage.capitalize,
      short: true
    }, {
      title: 'Revision',
      value: revision,
      short: true
    }],
    fallback: application + ' was successfully deployed.'
  }]
}
end

#payload_for_updatingObject

Suppress updating message.



6
7
8
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 6

def payload_for_updating
  nil
end

#previous_revisionObject

Get previous revision



21
22
23
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 21

def previous_revision
  fetch(:previous_revision)
end

#repoObject

Get individual parts of the repo_url



26
27
28
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 26

def repo
  repo_url.match(/(git@|https:\/\/)(?<host>([\w\.@]+))(\/|:)(?<owner>[\w,\-,\_]+)\/(?<repo>[\w,\-,\_]+)(.git){0,1}((\/){0,1})/)
end

#revisionObject

Get information about the revision being deployed



31
32
33
34
35
36
37
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 31

def revision
  if repo.nil? || current_revision.nil?
    'Unknown'
  else
    current_revision_url
  end
end

#revision_compare_urlObject

Get revision comparison



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capistrano/wearerequired/slackistrano_extended_git_messaging.rb', line 53

def revision_compare_url
  "<https://%{host}/%{owner}/%{repo}/%{compare}/%{previous_revision}...%{current_revision}|%{revision_short}>" % {
    :host => repo[:host],
    :owner => repo[:owner],
    :repo => repo[:repo],
    :compare => 'bitbucket.org' == repo[:host] ? 'branches/compare' : 'compare',
    :current_revision => current_revision,
    :previous_revision => previous_revision,
    :revision_short => previous_revision[0..7] + '...' + current_revision[0..7]
  }
end