robut-shipr 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e90b08d4b0e98cb83bd1f2b1c37e59b384039273
4
+ data.tar.gz: d9407fa3b3c92829d5d1040ffd77a0c07711d6e6
5
+ SHA512:
6
+ metadata.gz: a30a36f868a5841db5365cd61746a36822aecc67552886346206ea7a934c0cd3a18b9abfa8dba6a54f83402f7bc0f74582a0422cc04364d951562572e63ac0dc
7
+ data.tar.gz: dc749b9049756695e38de5e3e130c62ade7b3b996a3241ef9e827ab24cba9ddfb0831169074566d6439081b7ade3e05c3dd68e8d8647cefc5bc616512ecc13a7
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in robut-shipr.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard-rspec'
8
+ end
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eric J. Holmes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Robut Shipr
2
+
3
+ A Robut plugin for [Shipr](http://github.com/ejholmes/shipr)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'robut-shipr'
11
+ ```
12
+
13
+ Add it to your Chatfile:
14
+
15
+ ```ruby
16
+ require 'robut/plugin/shipr'
17
+ Robut::Plugin.plugins << Robut::Plugin::Shipr
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ * `@robut deploy app`
23
+ * `@robut deploy app to staging`
24
+ * `@robut deploy app#feature-branch to staging`
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => [:spec]
5
+
6
+ require 'rspec/core/rake_task'
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ end
@@ -0,0 +1,3 @@
1
+ module RobutShipr
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'robut'
2
+ require 'json'
3
+ require 'httparty'
4
+ require 'hashie'
5
+
6
+ module Robut::Plugin
7
+ class Shipr
8
+ include Robut::Plugin
9
+
10
+ autoload :Configuration, 'robut/plugin/shipr/configuration'
11
+ autoload :Deploy, 'robut/plugin/shipr/deploy'
12
+
13
+ DEPLOYING = 'Deploying %s to %s: %s'
14
+
15
+ class << self
16
+
17
+ # Public: The plugin configuration
18
+ #
19
+ # Returns Robut::Plugin::Shipr::Configuration
20
+ def configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ # Public: Configure the plugin
25
+ #
26
+ # Examples
27
+ #
28
+ # Robut::Plugin::Shipr.configure do |config|
29
+ # config.endpoint = 'http://shipr.company.com'
30
+ # end
31
+ def configure
32
+ yield configuration
33
+ end
34
+ end
35
+
36
+ desc "deploy <repo> - Fuck it! We'll do it live!"
37
+ match /^deploy (\S+?)(!)?$/, sent_to_me: true do |repo, force|
38
+ deploy repo, force: force
39
+ end
40
+
41
+ desc "deploy <repo> to <environment> - Deploy the repo to the specified environment."
42
+ match /^deploy (\S+?) to (\S+?)(!)?$/, sent_to_me: true do |repo, environment, force|
43
+ deploy repo, environment: environment, force: force
44
+ end
45
+
46
+ private
47
+
48
+ def deploy(*args)
49
+ deploy = Deploy.new(*args)
50
+ response = deploy.perform.parsed_response
51
+ reply DEPLOYING % [deploy.name, deploy.environment, "#{self.class.configuration.api_base}/deploys/#{response['id']}"]
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ module Robut::Plugin
2
+ class Shipr::Configuration
3
+ # A Proc object used to determine the branch to deploy based on an
4
+ # environment.
5
+ attr_accessor :branch
6
+
7
+ # A string used to delimit the repo name and the branch name
8
+ attr_accessor :branch_delimiter
9
+
10
+ # The base url where shipr is located.
11
+ attr_accessor :api_base
12
+
13
+ # The basic auth credentials.
14
+ attr_accessor :credentials
15
+
16
+ # The github organization to use when determining the repo.
17
+ attr_accessor :github_organization
18
+
19
+ def initialize
20
+ @branch_delimiter = '#'.freeze
21
+ @api_base = ENV['SHIPR_BASE'] || 'https://shipr.herokuapp.com'
22
+ @github_organization = ENV['SHIPR_GITHUB_ORG']
23
+ end
24
+
25
+ def branch
26
+ @branch ||= lambda { |environment|
27
+ case environment.to_sym
28
+ when :staging
29
+ :develop
30
+ else
31
+ :master
32
+ end
33
+ }
34
+ end
35
+
36
+ def credentials
37
+ @credentials ||= begin
38
+ auth = ENV['SHIPR_AUTH'].to_s.split(':')
39
+ { username: auth[0], password: auth[1] }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,59 @@
1
+ module Robut::Plugin
2
+ class Shipr::Deploy
3
+ attr_reader :name, :branch, :options
4
+
5
+ def initialize(name, options = {})
6
+ @name, @branch = name.split(configuration.branch_delimiter)
7
+ @options = options
8
+ end
9
+
10
+ def perform
11
+ body = {
12
+ repo: repo,
13
+ config: config,
14
+ branch: branch
15
+ }
16
+
17
+ HTTParty.post endpoint,
18
+ body: body.to_json,
19
+ headers: { 'Content-Type' => 'application/json' },
20
+ basic_auth: configuration.credentials
21
+ end
22
+
23
+ def environment
24
+ options[:environment] || 'production'
25
+ end
26
+
27
+ def force
28
+ options[:force] || false
29
+ end
30
+
31
+ def branch
32
+ @branch ||= configuration.branch[environment]
33
+ end
34
+
35
+ private
36
+
37
+ def config
38
+ config = { 'ENVIRONMENT' => environment }
39
+ config.merge!('FORCE' => '1') if force
40
+ config
41
+ end
42
+
43
+ def endpoint
44
+ "#{configuration.api_base}/api/deploys"
45
+ end
46
+
47
+ def nwo
48
+ name =~ /\// ? name : "#{configuration.github_organization}/#{name}"
49
+ end
50
+
51
+ def repo
52
+ "git@github.com:#{nwo}.git"
53
+ end
54
+
55
+ def configuration
56
+ Robut::Plugin::Shipr.configuration
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'robut-shipr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "robut-shipr"
8
+ spec.version = RobutShipr::VERSION
9
+ spec.authors = ["Eric J. Holmes"]
10
+ spec.email = ["eric@ejholmes.net"]
11
+ spec.description = %q{A Robut plugin for shipr}
12
+ spec.summary = %q{A Robut plugin for shipr}
13
+ spec.homepage = "https://github.com/ejholmes/robut-shipr"
14
+ spec.license = "MIT"
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_dependency "robut"
22
+ spec.add_dependency "json"
23
+ spec.add_dependency "httparty"
24
+ spec.add_dependency "hashie"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "webmock"
30
+ spec.add_development_dependency "rack-test"
31
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Robut::Plugin::Shipr do
4
+ let(:reply_to) { double('reply_to').as_null_object }
5
+ let(:plugin) { described_class.new(reply_to) }
6
+
7
+ before do
8
+ reply_to.stub_chain :connection, :config, mention_name: 'robut'
9
+ end
10
+
11
+ describe '.handle' do
12
+ [
13
+ {
14
+ message: '@robut deploy app to production',
15
+ parsed: { app: 'app', env: 'production', branch: 'master' },
16
+ reply: 'Deploying app to production: https://shipr.herokuapp.com/deploys/:id'
17
+ },
18
+ {
19
+ message: '@robut deploy app',
20
+ parsed: { app: 'app', env: 'production', branch: 'master' },
21
+ reply: 'Deploying app to production: https://shipr.herokuapp.com/deploys/:id'
22
+ },
23
+ {
24
+ message: '@robut deploy app to staging',
25
+ parsed: { app: 'app', env: 'staging', branch: 'develop' },
26
+ reply: 'Deploying app to staging: https://shipr.herokuapp.com/deploys/:id'
27
+ },
28
+ {
29
+ message: '@robut deploy app#topic to staging',
30
+ parsed: { app: 'app', env: 'staging', branch: 'topic' },
31
+ reply: 'Deploying app to staging: https://shipr.herokuapp.com/deploys/:id'
32
+ },
33
+ {
34
+ message: '@robut deploy app!',
35
+ parsed: { app: 'app', config: { 'ENVIRONMENT' => 'production', 'FORCE' => '1' }, branch: 'master' },
36
+ reply: 'Deploying app to production: https://shipr.herokuapp.com/deploys/:id'
37
+ },
38
+ {
39
+ message: '@robut deploy app to staging!',
40
+ parsed: { app: 'app', config: { 'ENVIRONMENT' => 'staging', 'FORCE' => '1' }, branch: 'develop' },
41
+ reply: 'Deploying app to staging: https://shipr.herokuapp.com/deploys/:id'
42
+ }
43
+ ].each do |test|
44
+ context "with the message: #{test[:message]}" do
45
+ let(:message) { test[:message] }
46
+
47
+ it "deploys the #{test[:parsed][:branch]} branch of #{test[:parsed][:app]} to the #{test[:parsed][:env]} environment" do
48
+ stub_shipr_request(test[:parsed])
49
+ expect_reply(test[:reply])
50
+ plugin.handle(Time.now, 'eric', test[:message])
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path('../../lib/robut/plugin/shipr', __FILE__)
2
+ require 'webmock/rspec'
3
+ require 'securerandom'
4
+ require 'net/http'
5
+ require 'rack/test'
6
+
7
+ Robut::Web.set :show_exceptions, false
8
+ Robut::Web.set :raise_errors, true
9
+
10
+ RSpec.configure do |config|
11
+ config.before do
12
+ ENV['SHIPR_GITHUB_ORG'] = 'remind101'
13
+ ENV['SHIPR_AUTH'] = ':Ak6th'
14
+ ENV['BASE_URL'] = 'http://robut.test'
15
+ end
16
+
17
+ config.include(Module.new do
18
+ def stub_shipr_request(options = {})
19
+ body = {
20
+ :repo => "git@github.com:remind101/#{options[:app]}.git",
21
+ :config => options[:config] || { 'ENVIRONMENT' => options[:env] },
22
+ :branch => options[:branch]
23
+ }
24
+ stub_request(:post, "https://:Ak6th@shipr.herokuapp.com/api/deploys")
25
+ .with(body: body.to_json)
26
+ .to_return(body: { id: ':id' }.to_json, headers: { 'Content-Type' => 'application/json' })
27
+ end
28
+
29
+ def expect_reply(reply)
30
+ reply_to.should_receive(:reply).with(reply, nil)
31
+ end
32
+ end)
33
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robut-shipr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Eric J. Holmes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: robut
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-test
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Robut plugin for shipr
140
+ email:
141
+ - eric@ejholmes.net
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .rspec
148
+ - Gemfile
149
+ - Guardfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - lib/robut-shipr/version.rb
154
+ - lib/robut/plugin/shipr.rb
155
+ - lib/robut/plugin/shipr/configuration.rb
156
+ - lib/robut/plugin/shipr/deploy.rb
157
+ - robut-shipr.gemspec
158
+ - spec/shipr_spec.rb
159
+ - spec/spec_helper.rb
160
+ homepage: https://github.com/ejholmes/robut-shipr
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.0.14
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: A Robut plugin for shipr
184
+ test_files:
185
+ - spec/shipr_spec.rb
186
+ - spec/spec_helper.rb