Class: Capistrano::DeployHooks::Messengers::Mattermost

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capistrano/deploy_hooks/messengers/mattermost.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cap, opts) ⇒ Mattermost

Returns a new instance of Mattermost.



10
11
12
13
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 10

def initialize(cap, opts)
  @cap  = cap
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 8

def opts
  @opts
end

Instance Method Details

#applicationObject



60
61
62
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 60

def application
  fetch(:application)
end

#branchObject



56
57
58
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 56

def branch
  fetch(:branch)
end

#deployerObject



52
53
54
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 52

def deployer
  ENV["USER"] || ENV["USERNAME"]
end

#payload_for_failedObject



44
45
46
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 44

def payload_for_failed
  { text: "#{deployer} has failed to #{deploying? ? 'deploy' : 'rollback'} branch #{branch} of #{application} to #{stage}" }
end

#payload_for_revertedObject



40
41
42
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 40

def payload_for_reverted
  { text: "#{deployer} has finished rolling back branch of #{application} to #{stage}" }
end

#payload_for_revertingObject



32
33
34
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 32

def payload_for_reverting
  { text: "#{deployer} has started rolling back branch #{branch} of #{application} to #{stage}" }
end

#payload_for_updatedObject



36
37
38
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 36

def payload_for_updated
  { text: "#{deployer} has finished deploying branch #{branch} of #{application} to #{stage}" }
end

#payload_for_updatingObject



28
29
30
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 28

def payload_for_updating
  { text: "#{deployer} has started deploying branch #{branch} of #{application} to #{stage}" }
end

#payloads_for(action) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 15

def payloads_for(action)
  method = "payload_for_#{action}"
  return if !respond_to?(method)

  pl = (opts[:payload] || {}).merge(username: "Capistrano").merge(send(method))

  channels = Array(opts[:channels])

  payloads = channels.map{ |c| pl.merge(channel: c) }
  payloads = [pl] if payloads.empty?
  payloads
end

#stageObject



64
65
66
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 64

def stage
  fetch(:stage, '')
end

#webhook_for(_) ⇒ Object



48
49
50
# File 'lib/capistrano/deploy_hooks/messengers/mattermost.rb', line 48

def webhook_for(_)
  opts[:webhook_uri]
end