twist_capistrano 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hipchat.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ TwistCapistrano
2
+ ===============
@@ -0,0 +1,33 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module TwistCapistrano
5
+
6
+ class Client
7
+
8
+ def initialize(twist_secret)
9
+ @twist_secret = twist_secret
10
+ end
11
+
12
+ def send(message, twist_msg_id)
13
+ return if @twist_secret.nil? || @twist_secret.empty?
14
+
15
+ uri = URI.parse("https://api.twist.io/api/v1/hook/capistrano?secret=#{@twist_secret}")
16
+ req = Net::HTTP::Post.new(uri.request_uri)
17
+
18
+ req.body = {
19
+ 'message' => "#{message}",
20
+ 'parent_id' => twist_msg_id.to_s
21
+ }.to_json
22
+
23
+ http = Net::HTTP.new(uri.host, uri.port)
24
+ http.use_ssl = true
25
+ res = http.start {|http| http.request(req) }
26
+
27
+ response = JSON.parse(res.body)
28
+ response['id']
29
+ rescue
30
+ puts "Sending message to Twist failed."
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,64 @@
1
+ require 'twist_capistrano'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ set :twist_send_notification, false
5
+ set :twist_message_id, nil
6
+
7
+ namespace :twist do
8
+ task :deploy_starts do
9
+ set :twist_send_notification, true
10
+ twist_msg_id = send("#{who} is deploying #{app}")
11
+ set :twist_message_id, twist_msg_id
12
+ end
13
+
14
+ task :deploy_finished do
15
+ if twist_send_notification
16
+ send("Deploy finished.")
17
+ end
18
+ set :twist_send_notification, false
19
+ set :twist_message_id, nil
20
+ end
21
+
22
+ task :deploy_failed do
23
+ if twist_send_notification
24
+ send("Deploy failed.")
25
+ end
26
+ set :twist_send_notification, false
27
+ set :twist_message_id, nil
28
+ end
29
+
30
+ def send(message)
31
+ set :twist_client, TwistCapistrano::Client.new(twist_secret) if fetch(:twist_client, nil).nil?
32
+ twist_client.send(message, twist_message_id)
33
+ end
34
+
35
+ def who
36
+ if (user = %x{git config user.name}.strip) != ""
37
+ user
38
+ else
39
+ "Someone"
40
+ end
41
+ end
42
+
43
+ def app
44
+ if fetch(:branch, nil)
45
+ "#{application}/#{branch}"
46
+ else
47
+ application
48
+ end
49
+ end
50
+
51
+ def repo
52
+ if fetch(:repository,nil)
53
+ repository
54
+ else
55
+ "repository"
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ before "deploy", "twist:deploy_starts"
62
+ after "deploy", "twist:deploy_finished"
63
+ after "on_rollback", "twist:deploy:failed"
64
+ end
@@ -0,0 +1,3 @@
1
+ module TwistCapistrano
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twist_capistrano/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twist_capistrano"
8
+ spec.version = TwistCapistrano::VERSION
9
+ spec.authors = ["Twist/Copper"]
10
+ spec.email = ["---"]
11
+ spec.description = %q{Ruby library to interact Capistrano with Twist.io}
12
+ spec.summary = %q{Ruby library to interact Capistrano with Twist.io}
13
+ #spec.homepage = "---"
14
+ #spec.license = "---"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twist_capistrano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Twist/Copper
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Ruby library to interact Capistrano with Twist.io
47
+ email:
48
+ - ! '---'
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - README.md
56
+ - lib/twist_capistrano.rb
57
+ - lib/twist_capistrano/capistrano.rb
58
+ - lib/twist_capistrano/version.rb
59
+ - twist_capistrano.gemspec
60
+ homepage:
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.23
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Ruby library to interact Capistrano with Twist.io
84
+ test_files: []