bard 0.19.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02b8af12d5e8b586b968b4ca9013bf254721792e
4
+ data.tar.gz: 0ca8d631a309b80d8d159a72db5a24296c5dbd00
5
+ SHA512:
6
+ metadata.gz: b53174e6149124a50d836ed7209df93338f0024493cb3b9f283dfcf9c3e35b0d2bd8f9ff9a5eb93a413016b21ff13ab21fe4d808f8fb1756ffe561fd534375ce
7
+ data.tar.gz: 95d3290c6155ebb4381e06b744f475d90ebb620c4cbe1f01339e0bdc81945c6f0fd74b2aa8cfb5f46273ff0c433a3fa7ac70395de49732521554de8cf888226d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.19.2
1
+ 0.20.0
data/bard.gemspec CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.add_dependency "thor", "0.11.7"
18
18
  gem.add_dependency "capistrano", "2.5.10"
19
19
  gem.add_dependency "rvm-capistrano"
20
- gem.add_dependency "grit", "1.1.1"
21
20
  gem.add_dependency "systemu", ">=1.2.0"
22
21
  gem.add_dependency "term-ansicolor", ">=1.0.3"
23
22
  gem.add_dependency "bard-rake", ">=0.1.1"
data/bin/bard CHANGED
@@ -1,9 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
2
+ require "rubygems"
4
3
  require File.dirname(__FILE__) + "/../lib/bard"
5
- begin
6
- Bard.start ARGV
7
- rescue Bard::Error => e
8
- fatal e.message
9
- end
4
+ Bard::CLI.start ARGV
5
+
data/lib/bard.rb CHANGED
@@ -1,54 +1,16 @@
1
1
  $:.unshift File.expand_path(File.dirname(__FILE__))
2
- require 'rubygems'
3
- require 'term/ansicolor'
4
- require 'net/http'
5
- require 'systemu'
6
- require 'grit'
7
- require 'thor'
8
-
9
- require 'bard/error'
10
- require 'bard/git'
11
- require 'bard/io'
12
-
13
- require 'bard/ssh_delegation'
14
-
15
- class Bard < Thor
16
- include BardGit
17
- include BardIO
18
-
19
- VERSION = File.read(File.expand_path(File.dirname(__FILE__) + "../../VERSION")).chomp
20
-
21
- desc "install [PROJECT NAME]", "install and bootstrap existing project"
22
- def install(project_name)
23
- auto_update!
24
- command = <<-BASH
25
- git clone git@git.botandrose.com:#{project_name}.git
26
-
27
- cd #{project_name}
28
- git checkout integration
29
- rvm . do bundle
30
- rvm . do bundle exec rake bootstrap
31
-
32
- sudo -s <#{"<EOF"}
33
- echo "<VirtualHost *:80>
34
- ServerName #{project_name}.local
35
- DocumentRoot `pwd`/public
36
- </VirtualHost>" > /etc/apache2/sites-available/#{project_name}
37
- a2ensite #{project_name}
38
- apache2ctl restart
39
-
40
- if ! grep "#{project_name}.local" /etc/hosts; then
41
- echo 127.0.0.1 #{project_name}.local >> /etc/hosts
42
- fi
43
- EOF
44
- BASH
45
- exec command
46
- end
2
+
3
+ module Bard; end
4
+
5
+ require "bard/base"
6
+ require "bard/error"
7
+ require "bard/git"
8
+
9
+ class Bard::CLI < Thor
10
+ include Bard::CLI::Git
47
11
 
48
12
  desc "data [FROM=production, TO=local]", "copy database and assets from FROM to TO"
49
13
  def data(from = "production", to = "local")
50
- ensure_sanity!(true)
51
-
52
14
  if to == "local"
53
15
  if from == "production" and heroku?
54
16
  exec "heroku db:pull --confirm #{project_name}"
@@ -66,10 +28,6 @@ EOF
66
28
  method_options %w( verbose -v ) => :boolean
67
29
  desc "pull", "pull changes to your local machine"
68
30
  def pull
69
- ensure_sanity!
70
-
71
- warn NonFastForwardError unless fast_forward_merge?("origin/#{current_branch}")
72
-
73
31
  run_crucial "git pull --rebase origin #{current_branch}", options.verbose?
74
32
  run_crucial "bundle && bundle exec rake bootstrap", options.verbose?
75
33
  end
@@ -77,10 +35,7 @@ EOF
77
35
  method_options %w( verbose -v ) => :boolean
78
36
  desc "push", "push local changes out to the remote"
79
37
  def push
80
- ensure_sanity!
81
-
82
38
  raise NonFastForwardError unless fast_forward_merge?("origin/#{current_branch}")
83
-
84
39
  run_crucial "git push origin #{current_branch}", true
85
40
  end
86
41
 
@@ -165,53 +120,33 @@ EOF
165
120
  end
166
121
 
167
122
  private
168
- def heroku?
169
- `git remote -v`.include? "production\tgit@heroku.com:"
170
- end
171
123
 
172
- def ci_host
173
- "http://botandrose:thecakeisalie!@ci.botandrose.com/job/#{project_name}"
174
- end
175
-
176
- def has_ci?
177
- `curl -s -I #{ci_host}/?token=botandrose` =~ /\b200 OK\b/
178
- end
124
+ def heroku?
125
+ `git remote -v`.include? "production\tgit@heroku.com:"
126
+ end
179
127
 
180
- def start_ci
181
- `curl -s -I -X POST #{ci_host}/build?token=botandrose`
182
- end
128
+ def ci_host
129
+ "http://botandrose:thecakeisalie!@ci.botandrose.com/job/#{project_name}"
130
+ end
183
131
 
184
- def get_last_build_number
185
- response = `curl -s #{ci_host}/lastBuild/api/xml?token=botandrose`
186
- response.match(/<number>(\d+)<\/number>/)
187
- $1 ? $1.to_i : nil
188
- end
132
+ def has_ci?
133
+ `curl -s -I #{ci_host}/?token=botandrose` =~ /\b200 OK\b/
134
+ end
189
135
 
190
- def get_last_time_elapsed
191
- response = `curl -s #{ci_host}/lastStableBuild/api/xml?token=botandrose`
192
- response.match(/<duration>(\d+)<\/duration>/)
193
- $1 ? $1.to_i / 1000 : nil
194
- end
136
+ def start_ci
137
+ `curl -s -I -X POST #{ci_host}/build?token=botandrose`
138
+ end
195
139
 
196
- def ensure_sanity!(dirty_ok = false)
197
- auto_update!
198
- raise NotInProjectRootError unless File.directory? ".git"
199
- raise OnMasterBranchError if current_branch == "master"
200
- raise WorkingTreeDirtyError unless `git status`.include? "working directory clean" unless dirty_ok
201
- end
140
+ def get_last_build_number
141
+ response = `curl -s #{ci_host}/lastBuild/api/xml?token=botandrose`
142
+ response.match(/<number>(\d+)<\/number>/)
143
+ $1 ? $1.to_i : nil
144
+ end
202
145
 
203
- def auto_update!
204
- match = `curl -s http://rubygems.org/api/v1/gems/bard.json`.match(/"version":"([0-9.]+)"/)
205
- return unless match
206
- required = match[1]
207
- if Bard::VERSION != required
208
- original_command = [ENV["_"], @_invocations[Bard].first, ARGV].flatten.join(" ")
209
- puts "bard gem is out of date... updating to new version"
210
- exec "gem install bard && #{original_command}"
211
- end
212
- if options.verbose?
213
- puts green("#{"bard".ljust(9)} (#{Bard::VERSION})")
214
- end
215
- end
146
+ def get_last_time_elapsed
147
+ response = `curl -s #{ci_host}/lastStableBuild/api/xml?token=botandrose`
148
+ response.match(/<duration>(\d+)<\/duration>/)
149
+ $1 ? $1.to_i / 1000 : nil
150
+ end
216
151
  end
217
152
 
data/lib/bard/base.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "thor"
2
+ require "term/ansicolor"
3
+ require "systemu"
4
+
5
+ class Bard::CLI < Thor
6
+ include Term::ANSIColor
7
+
8
+ private
9
+
10
+ def fatal(message)
11
+ raise Bard::CLI::Error, red("!!! ") + message
12
+ end
13
+
14
+ def run_crucial(command, verbose = false)
15
+ status, stdout, stderr = systemu command
16
+ fatal "Running command: #{yellow(command)}: #{stderr}" if status.to_i.nonzero?
17
+ if verbose
18
+ $stdout.puts stdout
19
+ $stderr.puts stderr
20
+ end
21
+ stdout.chomp
22
+ end
23
+
24
+ def project_name
25
+ @project_name ||= File.expand_path(".").split("/").last
26
+ end
27
+ end
28
+
data/lib/bard/error.rb CHANGED
@@ -1,28 +1,23 @@
1
- class Bard < Thor
2
- {
3
- "NonFastForwardError" => "Someone has pushed some changes since you last pulled.\n Kindly run bard pull, ensure that your your changes still work, and try again",
4
- "MasterNonFastForwardError" => "The master branch has advanced since last deploy, probably due to a bugfix.\n Rebase your integration branch on top of it, and check for breakage.",
5
- "NotInProjectRootError" => "You are not in the project's root directory!",
6
- "OnMasterBranchError" => "You are on the master branch!\n This is almost always a bad idea. Please work on a topic branch. If you have made changes on this branch, please see Micah for assistance.",
7
- "WorkingTreeDirtyError" => "You have uncommitted changes!\n Please run git commit before attempting to push or pull.",
8
- "StagingDetachedHeadError" => "The staging server is on a detached HEAD!\n Please see Micah for assistance."
9
- }.each do |error, message|
10
- eval <<-RUBY
11
- class #{error} < Bard::Error
12
- def message
13
- %q{#{message}}
14
- end
1
+ class Bard::CLI < Thor
2
+ class NonFastForwardError < Bard::CLI::Error
3
+ def message
4
+ "Someone has pushed some changes since you last pulled.\n Kindly run bard pull, ensure that your your changes still work, and try again"
5
+ end
6
+ end
7
+
8
+ class MasterNonFastForwardError < Bard::CLI::Error
9
+ def message
10
+ "The master branch has advanced since last deploy, probably due to a bugfix.\n Rebase your integration branch on top of it, and check for breakage."
15
11
  end
16
- RUBY
17
12
  end
18
13
 
19
- class TestsFailedError < Bard::Error
14
+ class TestsFailedError < Bard::CLI::Error
20
15
  def message
21
16
  "Automated tests failed!\n See #{super} for more info."
22
17
  end
23
18
  end
24
19
 
25
- class TestsAbortedError < Bard::Error
20
+ class TestsAbortedError < Bard::CLI::Error
26
21
  def message
27
22
  "Automated tests aborted!\n See #{super} for more info."
28
23
  end
data/lib/bard/git.rb CHANGED
@@ -1,46 +1,22 @@
1
- module BardGit
1
+ module Bard::CLI::Git
2
2
  private
3
- def current_branch
4
- ref = `git symbolic-ref HEAD 2>&1`.chomp
5
- return false if ref =~ /^fatal:/
6
- ref.sub(/refs\/heads\//, '') # refs/heads/master ... we want "master"
7
- end
8
3
 
9
- def fast_forward_merge?(root = "origin/integration", branch = "HEAD")
10
- run_crucial "git fetch origin"
11
- root_head = run_crucial "git rev-parse #{root}"
12
- branch_head = run_crucial "git rev-parse #{branch}"
13
- @common_ancestor = find_common_ancestor root_head, branch_head
14
- @common_ancestor == root_head
15
- end
4
+ def current_branch
5
+ ref = `git symbolic-ref HEAD 2>&1`.chomp
6
+ return false if ref =~ /^fatal:/
7
+ ref.sub(/refs\/heads\//, '') # refs/heads/master ... we want "master"
8
+ end
16
9
 
17
- def find_common_ancestor(head1, head2)
18
- run_crucial "git merge-base #{head1} #{head2}"
19
- end
10
+ def fast_forward_merge?(root = "origin/integration", branch = "HEAD")
11
+ run_crucial "git fetch origin"
12
+ root_head = run_crucial "git rev-parse #{root}"
13
+ branch_head = run_crucial "git rev-parse #{branch}"
14
+ @common_ancestor = find_common_ancestor root_head, branch_head
15
+ @common_ancestor == root_head
16
+ end
20
17
 
21
- def changed_files(old_rev, new_rev)
22
- run_crucial("git diff #{old_rev} #{new_rev} --diff-filter=ACMRD --name-only").split("\n")
23
- end
24
-
25
- def submodule_dirty?
26
- @repo ||= Grit::Repo.new "."
27
- submodules = Grit::Submodule.config(@repo, @repo.head.name)
28
- submodules.any? do |name, submodule|
29
- Dir.chdir submodule["path"] do
30
- not `git status`.include? "working directory clean"
31
- end
32
- end
33
- end
34
-
35
- def submodule_unpushed?
36
- @repo ||= Grit::Repo.new "."
37
- submodules = Grit::Submodule.config(@repo, @repo.head.name)
38
- submodules.any? do |name, submodule|
39
- Dir.chdir submodule["path"] do
40
- `git fetch origin`
41
- submodule["id"] != `git rev-parse origin/#{current_branch}`.chomp
42
- end
43
- end
44
- end
18
+ def find_common_ancestor(head1, head2)
19
+ run_crucial "git merge-base #{head1} #{head2}"
20
+ end
45
21
  end
46
22
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.19.2
4
+ version: 0.20.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Micah Geisel
@@ -10,148 +9,116 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-06-22 00:00:00.000000000 Z
12
+ date: 2013-12-12 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- prerelease: false
17
- type: :runtime
18
15
  name: thor
19
- version_requirements: !ruby/object:Gem::Requirement
20
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
21
17
  requirements:
22
18
  - - '='
23
19
  - !ruby/object:Gem::Version
24
20
  version: 0.11.7
25
- requirement: !ruby/object:Gem::Requirement
26
- none: false
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - '='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 0.11.7
31
28
  - !ruby/object:Gem::Dependency
32
- prerelease: false
33
- type: :runtime
34
29
  name: capistrano
35
- version_requirements: !ruby/object:Gem::Requirement
36
- none: false
30
+ requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
32
  - - '='
39
33
  - !ruby/object:Gem::Version
40
34
  version: 2.5.10
41
- requirement: !ruby/object:Gem::Requirement
42
- none: false
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
43
38
  requirements:
44
39
  - - '='
45
40
  - !ruby/object:Gem::Version
46
41
  version: 2.5.10
47
42
  - !ruby/object:Gem::Dependency
48
- prerelease: false
49
- type: :runtime
50
43
  name: rvm-capistrano
51
- version_requirements: !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
44
  requirement: !ruby/object:Gem::Requirement
58
- none: false
59
45
  requirements:
60
- - - ! '>='
46
+ - - '>='
61
47
  - !ruby/object:Gem::Version
62
48
  version: '0'
63
- - !ruby/object:Gem::Dependency
64
- prerelease: false
65
49
  type: :runtime
66
- name: grit
50
+ prerelease: false
67
51
  version_requirements: !ruby/object:Gem::Requirement
68
- none: false
69
- requirements:
70
- - - '='
71
- - !ruby/object:Gem::Version
72
- version: 1.1.1
73
- requirement: !ruby/object:Gem::Requirement
74
- none: false
75
52
  requirements:
76
- - - '='
53
+ - - '>='
77
54
  - !ruby/object:Gem::Version
78
- version: 1.1.1
55
+ version: '0'
79
56
  - !ruby/object:Gem::Dependency
80
- prerelease: false
81
- type: :runtime
82
57
  name: systemu
83
- version_requirements: !ruby/object:Gem::Requirement
84
- none: false
58
+ requirement: !ruby/object:Gem::Requirement
85
59
  requirements:
86
- - - ! '>='
60
+ - - '>='
87
61
  - !ruby/object:Gem::Version
88
62
  version: 1.2.0
89
- requirement: !ruby/object:Gem::Requirement
90
- none: false
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
91
66
  requirements:
92
- - - ! '>='
67
+ - - '>='
93
68
  - !ruby/object:Gem::Version
94
69
  version: 1.2.0
95
70
  - !ruby/object:Gem::Dependency
96
- prerelease: false
97
- type: :runtime
98
71
  name: term-ansicolor
99
- version_requirements: !ruby/object:Gem::Requirement
100
- none: false
72
+ requirement: !ruby/object:Gem::Requirement
101
73
  requirements:
102
- - - ! '>='
74
+ - - '>='
103
75
  - !ruby/object:Gem::Version
104
76
  version: 1.0.3
105
- requirement: !ruby/object:Gem::Requirement
106
- none: false
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
107
80
  requirements:
108
- - - ! '>='
81
+ - - '>='
109
82
  - !ruby/object:Gem::Version
110
83
  version: 1.0.3
111
84
  - !ruby/object:Gem::Dependency
112
- prerelease: false
113
- type: :runtime
114
85
  name: bard-rake
115
- version_requirements: !ruby/object:Gem::Requirement
116
- none: false
86
+ requirement: !ruby/object:Gem::Requirement
117
87
  requirements:
118
- - - ! '>='
88
+ - - '>='
119
89
  - !ruby/object:Gem::Version
120
90
  version: 0.1.1
121
- requirement: !ruby/object:Gem::Requirement
122
- none: false
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
123
94
  requirements:
124
- - - ! '>='
95
+ - - '>='
125
96
  - !ruby/object:Gem::Version
126
97
  version: 0.1.1
127
98
  - !ruby/object:Gem::Dependency
128
- prerelease: false
129
- type: :development
130
99
  name: rspec
131
- version_requirements: !ruby/object:Gem::Requirement
132
- none: false
100
+ requirement: !ruby/object:Gem::Requirement
133
101
  requirements:
134
102
  - - ~>
135
103
  - !ruby/object:Gem::Version
136
104
  version: 1.3.0
137
- requirement: !ruby/object:Gem::Requirement
138
- none: false
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
139
108
  requirements:
140
109
  - - ~>
141
110
  - !ruby/object:Gem::Version
142
111
  version: 1.3.0
143
112
  - !ruby/object:Gem::Dependency
144
- prerelease: false
145
- type: :development
146
113
  name: cucumber
147
- version_requirements: !ruby/object:Gem::Requirement
148
- none: false
114
+ requirement: !ruby/object:Gem::Requirement
149
115
  requirements:
150
116
  - - ~>
151
117
  - !ruby/object:Gem::Version
152
118
  version: 0.9.0
153
- requirement: !ruby/object:Gem::Requirement
154
- none: false
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
155
122
  requirements:
156
123
  - - ~>
157
124
  - !ruby/object:Gem::Version
@@ -189,35 +156,33 @@ files:
189
156
  - features/support/grit_ext.rb
190
157
  - features/support/io.rb
191
158
  - lib/bard.rb
159
+ - lib/bard/base.rb
192
160
  - lib/bard/capistrano.rb
193
161
  - lib/bard/error.rb
194
162
  - lib/bard/git.rb
195
- - lib/bard/io.rb
196
- - lib/bard/ssh_delegation.rb
197
163
  - spec/bard_spec.rb
198
164
  - spec/spec_helper.rb
199
165
  homepage: https://github.com/botandrose/bard
200
166
  licenses: []
167
+ metadata: {}
201
168
  post_install_message:
202
169
  rdoc_options: []
203
170
  require_paths:
204
171
  - lib
205
172
  required_ruby_version: !ruby/object:Gem::Requirement
206
- none: false
207
173
  requirements:
208
- - - ! '>='
174
+ - - '>='
209
175
  - !ruby/object:Gem::Version
210
176
  version: '0'
211
177
  required_rubygems_version: !ruby/object:Gem::Requirement
212
- none: false
213
178
  requirements:
214
- - - ! '>='
179
+ - - '>='
215
180
  - !ruby/object:Gem::Version
216
181
  version: '0'
217
182
  requirements: []
218
183
  rubyforge_project:
219
- rubygems_version: 1.8.25
184
+ rubygems_version: 2.1.10
220
185
  signing_key:
221
- specification_version: 3
186
+ specification_version: 4
222
187
  summary: Tools for collaborating with Bot and Rose Design.
223
188
  test_files: []
data/lib/bard/io.rb DELETED
@@ -1,27 +0,0 @@
1
- module BardIO
2
- include Term::ANSIColor
3
- private
4
-
5
- def warn(message)
6
- message = message.new.message if message.superclass == Bard::Error
7
- $stderr.puts yellow("! ") + message
8
- end
9
-
10
- def fatal(message)
11
- raise Bard::Error, red("!!! ") + message
12
- end
13
-
14
- def run_crucial(command, verbose = false)
15
- status, stdout, stderr = systemu command
16
- fatal "Running command: #{yellow(command)}: #{stderr}" if status.to_i.nonzero?
17
- if verbose
18
- $stdout.puts stdout
19
- $stderr.puts stderr
20
- end
21
- stdout.chomp
22
- end
23
-
24
- def project_name
25
- @project_name ||= File.expand_path(".").split("/").last
26
- end
27
- end
@@ -1,31 +0,0 @@
1
- class Bard < Thor
2
- desc "install-authorized-keys", "!!! INTERNAL USE ONLY !!! run as sudo"
3
- def install_authorized_keys(source_user, dest_user)
4
- source = "/home/#{source_user}/.ssh/authorized_keys"
5
- dest = "/home/#{dest_user}/.ssh/authorized_keys"
6
-
7
- file = File.read(source)
8
- file.gsub! /gitosis-serve/, "bard delegate"
9
-
10
- File.open(dest, "w") { |f| f.write(file) }
11
- end
12
-
13
- desc "delegate", "!!! INTERNAL USER ONLY !!!"
14
- def delegate(key)
15
- command = ENV['SSH_ORIGINAL_COMMAND']
16
-
17
- case command
18
- when /^scp -f (\w+)\.sql\.gz$/
19
- project = $1
20
- `#{command_for("staging", "cd #{project} && rake db:dump RAILS_ENV=staging && gzip -9f db/data.sql")}`
21
- command = "scp -f ~/#{project}/db/data.sql.gz"
22
- end
23
-
24
- exec command_for("staging", command)
25
- end
26
-
27
- private
28
- def command_for(user, command)
29
- %(sudo -H -u #{user} bash -c "cd ~ && #{command}")
30
- end
31
- end