Skip to content

Commit

Permalink
Various fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiamalonni committed Jul 11, 2019
1 parent 2c5f805 commit cb606dc
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 103 deletions.
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in capistrano-telegram.gemspec
gemspec

gem 'pry'
gem 'awesome_print'
gem 'telegram-bot-ruby'
gemspec
11 changes: 6 additions & 5 deletions capistrano-telegram.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# coding: utf-8
# -*- encoding: 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::Telegram::VERSION
spec.version = '1.0.2'
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.files = `git ls-files`.split($/)
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_dependency 'capistrano', '>= 3.8.1'
spec.add_dependency 'telegram-bot-ruby', "~> 0.8"

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
end
37 changes: 37 additions & 0 deletions lib/capistrano/messaging/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Capistrano
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
48 changes: 48 additions & 0 deletions lib/capistrano/messaging/telegram.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require_relative 'helpers'

module Capistrano
module Messaging
class Telegram
include Helpers

extend Forwardable
def_delegators :env, :fetch

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
9 changes: 6 additions & 3 deletions lib/capistrano/telegram.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'telegram/messaging/base'
require_relative 'messaging/telegram'

require 'telegram/bot'

Expand All @@ -7,10 +7,13 @@
module Capistrano
class Telegram

extend Forwardable
def_delegators :env, :fetch

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
@message = Capistrano::Messaging::Telegram.new
end

def send(action)
Expand All @@ -20,7 +23,7 @@ def send(action)

private
def send_to_telegram(message)
Telegram::Bot::Client.run(@telegram_bot_key) do |bot|
::Telegram::Bot::Client.run(@telegram_bot_key) do |bot|
bot.api.send_message(chat_id: @telegram_chat_id, text: message)
end
end
Expand Down
47 changes: 0 additions & 47 deletions lib/capistrano/telegram/messaging/base.rb

This file was deleted.

38 changes: 0 additions & 38 deletions lib/capistrano/telegram/messaging/helpers.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/capistrano/telegram/version.rb

This file was deleted.

Binary file removed misc/capistrano-icon.png
Binary file not shown.

0 comments on commit cb606dc

Please sign in to comment.