Class: Teamistrano::Notifier
- Inherits:
-
Object
- Object
- Teamistrano::Notifier
- Defined in:
- lib/teamistrano/notifier.rb
Constant Summary collapse
- DEFAULT_COLOR =
blue
"0033CC"- GREEN =
"00CC66"- RED =
"CC0000"
Instance Method Summary collapse
-
#get_body ⇒ Object
Get the body of the POST message as JSON.
-
#get_msg ⇒ Object
Get the full message to be delieved.
-
#initialize(env) ⇒ Notifier
constructor
A new instance of Notifier.
-
#notify_failed ⇒ Object
Send notice that deployment failed.
-
#notify_finishing ⇒ Object
Send notice that deployment finished.
-
#notify_finishing_rollback ⇒ Object
Send notice that deployment rollback finished.
-
#notify_reverting ⇒ Object
Send notice that deployment is reverting.
-
#notify_updating ⇒ Object
Send notice that deployment started.
-
#post ⇒ Object
Post to Teams.
Constructor Details
#initialize(env) ⇒ Notifier
Returns a new instance of Notifier.
13 14 15 16 17 18 |
# File 'lib/teamistrano/notifier.rb', line 13 def initialize( env ) @env = env @settings = Teamistrano::Settings.new( @env ) @color = DEFAULT_COLOR @msg = "" end |
Instance Method Details
#get_body ⇒ Object
Get the body of the POST message as JSON.
61 62 63 64 65 66 67 |
# File 'lib/teamistrano/notifier.rb', line 61 def get_body return { 'title' => "Deployment Notice", 'text' => get_msg, 'themeColor' => @color }.to_json end |
#get_msg ⇒ Object
Get the full message to be delieved.
54 55 56 57 58 |
# File 'lib/teamistrano/notifier.rb', line 54 def get_msg return "#{@msg} for #{@settings.application}. (#{@settings.stage}) \n Branch: #{@settings.branch} \n Deployed by: #{@settings.deployer}" end |
#notify_failed ⇒ Object
Send notice that deployment failed.
47 48 49 50 51 |
# File 'lib/teamistrano/notifier.rb', line 47 def notify_failed @color = RED @msg = "Deployment Failed" post end |
#notify_finishing ⇒ Object
Send notice that deployment finished.
34 35 36 37 38 |
# File 'lib/teamistrano/notifier.rb', line 34 def notify_finishing @color = GREEN @msg = "Deployment Finished" post end |
#notify_finishing_rollback ⇒ Object
Send notice that deployment rollback finished.
41 42 43 44 |
# File 'lib/teamistrano/notifier.rb', line 41 def notify_finishing_rollback @msg = "Deployment Rollback Finished" post end |
#notify_reverting ⇒ Object
Send notice that deployment is reverting.
28 29 30 31 |
# File 'lib/teamistrano/notifier.rb', line 28 def notify_reverting @msg = "Deployment Reverting" post end |
#notify_updating ⇒ Object
Send notice that deployment started.
22 23 24 25 |
# File 'lib/teamistrano/notifier.rb', line 22 def notify_updating @msg = "Deployment Started" post end |
#post ⇒ Object
Post to Teams.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/teamistrano/notifier.rb', line 70 def post uri = URI.parse( @settings.webhook_url ) request = Net::HTTP::Post.new( uri.path ) request.content_type = 'application/json' request.body = get_body n = Net::HTTP.new( uri.host, uri.port ) n.use_ssl = true # Send the payload to the endpoint. n.start { |http| http.request( request ) } end |