capistrano-telegram 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/capistrano-telegram.gemspec +25 -0
- data/lib/capistrano-telegram.rb +0 -0
- data/lib/capistrano/messaging/helpers.rb +36 -0
- data/lib/capistrano/messaging/telegram.rb +38 -0
- data/lib/capistrano/tasks/telegram.rake +41 -0
- data/lib/capistrano/telegram.rb +32 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51f372428b82746973575fb18d09242b0e68554538236c40e5a43442c0fb2d89
|
4
|
+
data.tar.gz: 8c07d69b7ac0e0313e069922b2018115e538066fe4430c1f120f86c5dff6dfeb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 183ea268064a60f241a9fa2fe409f24b2cd0a266c4d388fc551f3ebf4aad11ed43e5222969f692ae2ddb1de3430e0147a5fa2be160a3df4769dc22c8ac19623c
|
7
|
+
data.tar.gz: a819d96f3ffa3c274d1baadc3f7aeafd56ef8c4efe0e2f99d4ab50cb01fddc2b03a5e2508e4833d45772c2151d32944d21a37dd3ec3c59f02aed7561646300a0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Mattia Malonni
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Capistrano - Telegram Notification
|
2
|
+
|
3
|
+
Send notifications to Telegram about Capistrano deployments.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
1. Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'capistrano-telegram'
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
3. Require the library in your application's Capfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'capistrano/telegram'
|
23
|
+
```
|
24
|
+
|
25
|
+
### config/deploy.rb
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
set :telegram_bot_key, 'YOUR_BOT_ID'
|
29
|
+
set :telegram_chat_id, 'YOUR_BOT_CHAT_ID'
|
30
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "capistrano-telegram"
|
7
|
+
spec.version = '1.0.0'
|
8
|
+
spec.authors = ["Mattia Malonni"]
|
9
|
+
spec.email = ["mattia.malonni@gmail.com"]
|
10
|
+
spec.summary = %q{Notify Capistrano deployment to Telegram.}
|
11
|
+
spec.description = %q{Notify Capistrano deployment to Telegram.}
|
12
|
+
spec.homepage = "https://github.com/MattiaMalonni/capistrano-telegram"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'capistrano', '>= 3.8.1'
|
21
|
+
spec.add_dependency 'telegram-bot-ruby', "~> 0.8"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Messaging
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def icon_emoji
|
6
|
+
options.fetch(:icon_emoji, nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
def deployer
|
10
|
+
Etc.getpwnam(ENV['USER']).gecos
|
11
|
+
end
|
12
|
+
|
13
|
+
def branch
|
14
|
+
fetch(:branch)
|
15
|
+
end
|
16
|
+
|
17
|
+
def application
|
18
|
+
fetch(:application)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stage(default = 'an unknown stage')
|
22
|
+
fetch(:stage, default)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Return the elapsed running time as a string.
|
27
|
+
#
|
28
|
+
# Examples: 21-18:26:30, 15:28:37, 01:14
|
29
|
+
#
|
30
|
+
def elapsed_time
|
31
|
+
`ps -p #{$$} -o etime=`.strip
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'helpers'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Messaging
|
5
|
+
class Telegram
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :env, :fetch
|
10
|
+
|
11
|
+
def payload_for_updating
|
12
|
+
"#{deployer} has started deploying branch #{branch} of #{application} to #{stage}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def payload_for_reverting
|
16
|
+
"#{deployer} has started rolling back branch `#{branch}` of #{application} to #{stage}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def payload_for_updated
|
20
|
+
"#{deployer} has finished deploying branch #{branch} of #{application} to #{stage}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def payload_for_reverted
|
24
|
+
"#{deployer} has finished rolling back branch of #{application} to #{stage}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def payload_for_failed
|
28
|
+
"#{deployer} has failed to #{deploying? ? 'deploy' : 'rollback'} branch #{branch} of #{application} to #{stage}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def payload_for(action)
|
32
|
+
method = "payload_for_#{action}"
|
33
|
+
respond_to?(method) && send(method)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
namespace :telegram do
|
2
|
+
namespace :deploy do
|
3
|
+
|
4
|
+
desc 'Notify about updating deploy'
|
5
|
+
task :updating do
|
6
|
+
Capistrano::Telegram.new(self).send(:updating)
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'Notify about reverting deploy'
|
10
|
+
task :reverting do
|
11
|
+
Capistrano::Telegram.new(self).send(:reverting)
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Notify about updated deploy'
|
15
|
+
task :updated do
|
16
|
+
Capistrano::Telegram.new(self).send(:updated)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Notify about reverted deploy'
|
20
|
+
task :reverted do
|
21
|
+
Capistrano::Telegram.new(self).send(:reverted)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Notify about failed deploy'
|
25
|
+
task :failed do
|
26
|
+
Capistrano::Telegram.new(self).send(:failed)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Test Slack integration'
|
30
|
+
task :test => %i[updating updated reverting reverted failed] do
|
31
|
+
# all tasks run as dependencies
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
before 'deploy:updating', 'telegram:deploy:updating'
|
38
|
+
before 'deploy:reverting', 'telegram:deploy:reverting'
|
39
|
+
after 'deploy:finishing', 'telegram:deploy:updated'
|
40
|
+
after 'deploy:finishing_rollback', 'telegram:deploy:reverted'
|
41
|
+
after 'deploy:failed', 'telegram:deploy:failed'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'messaging/telegram'
|
2
|
+
|
3
|
+
require 'telegram/bot'
|
4
|
+
|
5
|
+
load File.expand_path('../tasks/telegram.rake', __FILE__)
|
6
|
+
|
7
|
+
module Capistrano
|
8
|
+
class Telegram
|
9
|
+
|
10
|
+
extend Forwardable
|
11
|
+
def_delegators :env, :fetch
|
12
|
+
|
13
|
+
def initialize(env)
|
14
|
+
@telegram_bot_key = fetch(:telegram_bot_key, nil)
|
15
|
+
@telegram_chat_id = fetch(:telegram_chat_id, nil)
|
16
|
+
@message = Capistrano::Messaging::Telegram.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def send(action)
|
20
|
+
payload = @message.payload_for(action)
|
21
|
+
send_to_telegram(payload)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def send_to_telegram(message)
|
26
|
+
::Telegram::Bot::Client.run(@telegram_bot_key) do |bot|
|
27
|
+
bot.api.send_message(chat_id: @telegram_chat_id, text: message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-telegram
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mattia Malonni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.8.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: telegram-bot-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Notify Capistrano deployment to Telegram.
|
70
|
+
email:
|
71
|
+
- mattia.malonni@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- capistrano-telegram.gemspec
|
82
|
+
- lib/capistrano-telegram.rb
|
83
|
+
- lib/capistrano/messaging/helpers.rb
|
84
|
+
- lib/capistrano/messaging/telegram.rb
|
85
|
+
- lib/capistrano/tasks/telegram.rake
|
86
|
+
- lib/capistrano/telegram.rb
|
87
|
+
homepage: https://github.com/MattiaMalonni/capistrano-telegram
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Notify Capistrano deployment to Telegram.
|
111
|
+
test_files: []
|