forked from itavia/capistrano-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6741f0d
Showing
13 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Gemfile.lock | ||
pkg | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in capistrano-telegram.gemspec | ||
gemspec | ||
|
||
gem 'pry' | ||
gem 'awesome_print' | ||
gem 'telegram-bot-ruby' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Mattia Malonni | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Capistrano - Telegram Notification | ||
|
||
Send notifications to Telegram about Capistrano deployments. | ||
|
||
## Installation | ||
|
||
1. Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'capistrano-telegram' | ||
``` | ||
|
||
2. Execute: | ||
|
||
``` | ||
$ bundle | ||
``` | ||
|
||
3. Require the library in your application's Capfile: | ||
|
||
```ruby | ||
require 'capistrano/telegram' | ||
``` | ||
|
||
### config/deploy.rb | ||
|
||
```ruby | ||
set :telegram_bot_key, 'YOUR_BOT_ID' | ||
set :telegram_chat_id, 'YOUR_BOT_CHAT_ID' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'capistrano/telegram/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "capistrano-telegram" | ||
spec.version = Capistrano::TelegramNotification::VERSION | ||
spec.authors = ["Mattia Malonni"] | ||
spec.email = ["[email protected]"] | ||
spec.summary = %q{Notify Capistrano deployment to Telegram.} | ||
spec.description = %q{Notify Capistrano deployment to Telegram.} | ||
spec.homepage = "https://github.com/MattiaMalonni/capistrano-telegram" | ||
spec.license = "MIT" | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_dependency "telegram-bot-ruby", "~> 0.8" | ||
spec.add_development_dependency "bundler", "~> 1.7" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace :telegram do | ||
namespace :deploy do | ||
|
||
desc 'Notify about updating deploy' | ||
task :updating do | ||
Capistrano::Telegram.new(self).send(:updating) | ||
end | ||
|
||
desc 'Notify about reverting deploy' | ||
task :reverting do | ||
Capistrano::Telegram.new(self).send(:reverting) | ||
end | ||
|
||
desc 'Notify about updated deploy' | ||
task :updated do | ||
Capistrano::Telegram.new(self).send(:updated) | ||
end | ||
|
||
desc 'Notify about reverted deploy' | ||
task :reverted do | ||
Capistrano::Telegram.new(self).send(:reverted) | ||
end | ||
|
||
desc 'Notify about failed deploy' | ||
task :failed do | ||
Capistrano::Telegram.new(self).send(:failed) | ||
end | ||
|
||
desc 'Test Slack integration' | ||
task :test => %i[updating updated reverting reverted failed] do | ||
# all tasks run as dependencies | ||
end | ||
|
||
end | ||
end | ||
|
||
before 'deploy:updating', 'telegram:deploy:updating' | ||
before 'deploy:reverting', 'telegram:deploy:reverting' | ||
after 'deploy:finishing', 'telegram:deploy:updated' | ||
after 'deploy:finishing_rollback', 'telegram:deploy:reverted' | ||
after 'deploy:failed', 'telegram:deploy:failed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative 'messaging/telegram/messaging/base' | ||
|
||
require 'telegram/bot' | ||
|
||
load File.expand_path('../tasks/telegram.rake', __FILE__) | ||
|
||
module Capistrano | ||
class Telegram | ||
|
||
def initialize(env) | ||
@telegram_bot_key = fetch(:telegram_bot_key, nil) | ||
@telegram_chat_id = fetch(:telegram_chat_id, nil) | ||
@message = Capistrano::Telegram::Messaging::Base.new | ||
end | ||
|
||
def send(action) | ||
payload = @message.payload_for(action) | ||
send_to_telegram(payload) | ||
end | ||
|
||
private | ||
def send_to_telegram(message) | ||
Telegram::Bot::Client.run(@telegram_bot_key) do |bot| | ||
bot.api.send_message(chat_id: @telegram_chat_id, text: message) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require_relative 'helpers' | ||
|
||
module Capistrano | ||
module Telegram | ||
module Messaging | ||
class Base | ||
include Helpers | ||
|
||
def payload_for_updating | ||
{ | ||
text: "#{deployer} has started deploying branch #{branch} of #{application} to #{stage}" | ||
} | ||
end | ||
|
||
def payload_for_reverting | ||
{ | ||
text: "#{deployer} has started rolling back branch #{branch} of #{application} to #{stage}" | ||
} | ||
end | ||
|
||
def payload_for_updated | ||
{ | ||
text: "#{deployer} has finished deploying branch #{branch} of #{application} to #{stage}" | ||
} | ||
end | ||
|
||
def payload_for_reverted | ||
{ | ||
text: "#{deployer} has finished rolling back branch of #{application} to #{stage}" | ||
} | ||
end | ||
|
||
def payload_for_failed | ||
{ | ||
text: "#{deployer} has failed to #{deploying? ? 'deploy' : 'rollback'} branch #{branch} of #{application} to #{stage}" | ||
} | ||
end | ||
|
||
def payload_for(action) | ||
method = "payload_for_#{action}" | ||
respond_to?(method) && send(method) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Capistrano | ||
module Telegram | ||
module Messaging | ||
module Helpers | ||
def icon_emoji | ||
options.fetch(:icon_emoji, nil) | ||
end | ||
|
||
def deployer | ||
default = ENV['USER'] || ENV['USERNAME'] | ||
fetch(:local_user, default) | ||
end | ||
|
||
def branch | ||
fetch(:branch) | ||
end | ||
|
||
def application | ||
fetch(:application) | ||
end | ||
|
||
def stage(default = 'an unknown stage') | ||
fetch(:stage, default) | ||
end | ||
|
||
# | ||
# Return the elapsed running time as a string. | ||
# | ||
# Examples: 21-18:26:30, 15:28:37, 01:14 | ||
# | ||
def elapsed_time | ||
`ps -p #{$$} -o etime=`.strip | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Capistrano | ||
module Telegram | ||
VERSION = '0.1.1' | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.