mina-teams 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 52d5ab87e43e54d122d668e025000887e8174a31ed7d2a033998773b85eb1515
4
+ data.tar.gz: cfb291f269ca0b4e73b7cc46f050051e74cb799e6d2930e0f52232c3941d4d1f
5
+ SHA512:
6
+ metadata.gz: e7afdbefd803102d58856ccb55a14ae568cff5063942cf771056d3004a7c681ce085ea227148beccce4e09a8c2f3dcdc5bb0b3b1dfae87e2690b162e8b4844d8
7
+ data.tar.gz: 0a33644c76db31104c8b72f002943018855d438eeca833ffe4c3e4ac4c7e728cd174df98861a748ba2eac24977284533e3fc00691ace701d288ff3629c258742
data/lib/mina/teams.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'mina/teams/tasks'
2
+ require 'mina/teams/version'
3
+
4
+ module Mina
5
+ module Teams
6
+ end
7
+ end
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'mina'
4
+
5
+ namespace :teams do
6
+ set :teams_url, -> { ENV['TEAMS_URL'] }
7
+ set :author, -> { ENV['GIT_AUTHOR_NAME'] || `git config user.name`.chomp }
8
+ set :commit, -> { ENV['GIT_COMMIT'] || `git rev-parse #{fetch(:branch)} | cut -c 1-7`.strip }
9
+ set :environment, -> { ENV['to'] }
10
+
11
+ task :starting do
12
+ notification = "#{fetch(:author).call} is deploying branch #{branch_name} to #{fetch(:environment).call}"
13
+ post_teams_channel(notification)
14
+ set(:start_time, Time.now)
15
+ end
16
+
17
+ task :finished do
18
+ end_time = Time.now
19
+ start_time = fetch(:start_time)
20
+ elapsed = end_time.to_i - start_time.to_i
21
+
22
+ notification = "#{fetch(:author).call} successfully deployed branch #{branch_name} in #{elapsed} seconds."
23
+ post_teams_channel(notification)
24
+ end
25
+
26
+ task :starting_restart do
27
+ notification = "#{fetch(:author).call} is restarting #{fetch(:environment).call} servers"
28
+ post_teams_channel(notification)
29
+ set(:start_time, Time.now)
30
+ end
31
+
32
+ task :finished_restart do
33
+ end_time = Time.now
34
+ start_time = fetch(:start_time)
35
+ elapsed = end_time.to_i - start_time.to_i
36
+
37
+ notification = "#{fetch(:author).call} successfully restarted #{fetch(:environment).call} servers in #{elapsed} seconds."
38
+ post_teams_channel(notification)
39
+ end
40
+
41
+ def branch_name
42
+ "#{fetch(:branch)} (#{fetch(:commit).call})"
43
+ end
44
+
45
+ def post_teams_channel(message)
46
+ uri = URI.parse(fetch(:teams_url))
47
+ http = Net::HTTP.new(uri.host, uri.port)
48
+ http.use_ssl = true
49
+
50
+ payload = {
51
+ text: message
52
+ }
53
+ headers = {'Content-Type': 'application/json'}
54
+
55
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
56
+ request.body = payload.to_json
57
+
58
+ # Call Teams webhook
59
+ resp = http.request(request)
60
+ if resp.code.to_i != 200
61
+ puts "Failed to notify Teams. Error [#{resp.body}], Status code [#{resp.code}]"
62
+ end
63
+ rescue => e
64
+ puts "Failed to notify Teams. Error #{e.inspect}"
65
+ end
66
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Mina
3
+ module Teams
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-teams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Coutinho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mina
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.8
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.8
69
+ description: Teams web hook from mina
70
+ email:
71
+ - rcoutinho@navisite.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/mina/teams.rb
77
+ - lib/mina/teams/tasks.rb
78
+ - lib/mina/teams/version.rb
79
+ homepage: https://github.com/VelocityCloud/mina-teams
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Teams web hook from mina
102
+ test_files: []