vigetlabs-provisional 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /pkg/
2
+ /doc/
3
+ /coverage/
4
+ *.gem
data/README.md CHANGED
@@ -27,6 +27,7 @@ Provisional is only tested on Mac OS X. It should also work on Linux. It is not
27
27
  --password, -p <s>: Password (for some SCMs, see below)
28
28
  --id, -i <s>: Id (for some SCMs, see below)
29
29
  --config, -c <s>: Config file (optional)
30
+ --private, -r: Private repository (for some SCMs, see documentation)
30
31
  --help, -h: Show this message
31
32
 
32
33
  The SCM option can be one of the following ("`project_name`" refers to the value of the --name option):
@@ -61,6 +62,8 @@ Options specified via the command line take precedence over options specified in
61
62
 
62
63
  To use [GitHub](http://github.com/), you will need to place your GitHub username and token in your Git configuration as described here: http://github.com/guides/local-github-config Since there is already this established convention for GitHub credentials, to prevent redundant configuration, Provisional does not use its own configuration options for GitHub access.
63
64
 
65
+ By default, repositories are publicly accessible. Use `--private` to make it private.
66
+
64
67
  ## Unfuddle
65
68
 
66
69
  To use [Unfuddle](http://unfuddle.com/) (for either Git or Subversion) you will need to specify the --domain, --id, --username and --password options. --domain is used to specify your unfuddle.com subdomain; --id is used to specify a project ID. Using a YAML file containing these options is recommended and should be helpful.
@@ -71,6 +74,13 @@ As of this writing (May 2009) [Beanstalk](http://beanstalkapp.com/)'s API is in
71
74
 
72
75
  To use Beanstalk you will need to specify the --domain, ---username and --password options. --domain is used to specify your beanstalkapp.com subdomain. Using a YAML file containing these options is recommended and should be helpful.
73
76
 
77
+ ## Acknowledgements
78
+
79
+ Provisional acknowledges the support of Viewers Like You, and also the following significant contributors:
80
+
81
+ * Clinton R. Nixon (crnixon)
82
+ * David Eisinger (dce)
83
+
74
84
  ## License
75
85
 
76
86
  Copyright (c) 2009 Mark Cornick of Viget Labs <mark@viget.com>
data/Rakefile CHANGED
@@ -43,7 +43,31 @@ rescue LoadError
43
43
  end
44
44
  end
45
45
 
46
+ begin
47
+ require 'reek/rake_task'
48
+ Reek::RakeTask.new do |t|
49
+ t.fail_on_error = true
50
+ t.verbose = false
51
+ t.source_files = 'lib/**/*.rb'
52
+ end
53
+ rescue LoadError
54
+ task :reek do
55
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
56
+ end
57
+ end
46
58
 
59
+ begin
60
+ require 'roodi'
61
+ require 'roodi_task'
62
+ RoodiTask.new do |t|
63
+ t.verbose = false
64
+ end
65
+ rescue LoadError
66
+ task :roodi do
67
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
68
+ end
69
+ end
70
+
47
71
  task :default => :test
48
72
 
49
73
  require 'rake/rdoctask'
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 2
3
2
  :minor: 1
4
- :patch: 6
3
+ :patch: 7
4
+ :major: 2
data/bin/provisional CHANGED
@@ -13,6 +13,7 @@ options = Trollop::options do
13
13
  opt :password, "Password (for some SCMs, see documentation)", :type => String
14
14
  opt :id, "Id (for some SCMs, see documentation)", :type => String
15
15
  opt :config, "Config file (optional)", :type => String
16
+ opt :private, "Private repository (for some SCMs, see documentation)"
16
17
  end
17
18
 
18
19
  Provisional::Project.new(options)
@@ -0,0 +1,23 @@
1
+ ---
2
+ Duplication:
3
+ exclude:
4
+ - create_repository
5
+ - find_template_path
6
+ - initialize
7
+ - load_options
8
+ - validate_options
9
+ - xml_payload
10
+
11
+ NestedIterators:
12
+ enabled: false
13
+
14
+ FeatureEnvy:
15
+ exclude:
16
+ - xml_payload
17
+
18
+ UtilityFunction:
19
+ exclude:
20
+ - xml_payload
21
+
22
+ LongMethod:
23
+ max_statements: 10
@@ -1,12 +1,13 @@
1
1
  require 'active_support'
2
+ require 'provisional'
2
3
  require 'uri'
3
4
  require 'yaml'
4
5
 
5
6
  module Provisional
6
7
  class Project
7
8
  attr_reader :options
8
-
9
- def initialize(options)
9
+
10
+ def load_options(options)
10
11
  @options = HashWithIndifferentAccess.new
11
12
  if options[:config]
12
13
  begin
@@ -15,12 +16,18 @@ module Provisional
15
16
  raise ArgumentError, "could not be loaded or parsed: #{options[:config]}"
16
17
  end
17
18
  end
18
- @options = @options.merge(options.reject{|k,v| v.nil?})
19
-
19
+ @options = @options.merge(options.reject{|key, value| value.nil?})
20
20
  @options[:scm] ||= 'git'
21
21
  @options[:template] ||= 'viget'
22
+ end
22
23
 
23
- unless is_valid_url?(@options['template'])
24
+ def find_template_path
25
+ begin
26
+ template_is_url = [URI::HTTP, URI::HTTPS].include?(URI.parse(@options['template']).class)
27
+ rescue URI::InvalidURIError
28
+ template_is_url = false
29
+ end
30
+ unless template_is_url
24
31
  if File.exist?(File.expand_path(@options['template']))
25
32
  @options['template_path'] = File.expand_path(@options['template'])
26
33
  else
@@ -30,7 +37,9 @@ module Provisional
30
37
  else
31
38
  @options['template_path'] = @options['template']
32
39
  end
40
+ end
33
41
 
42
+ def validate_options
34
43
  raise ArgumentError, "name must be specified" unless @options['name']
35
44
  raise ArgumentError, "already exists: #{@options['name']}" if File.exist?(@options['name'])
36
45
  raise ArgumentError, "already exists: #{@options['name']}.repo" if @options['scm'] == 'svn' && File.exist?("#{@options['name']}.repo")
@@ -40,21 +49,18 @@ module Provisional
40
49
  rescue MissingSourceFile
41
50
  raise ArgumentError, "is not supported: #{@options['scm']}"
42
51
  end
52
+ end
43
53
 
54
+ def provision
44
55
  scm_class = "Provisional::SCM::#{@options['scm'].classify}".constantize
45
- scm = scm_class.new(@options)
46
- scm.init
47
- scm.generate_rails
48
- scm.checkin
56
+ scm_class.new(@options).provision
49
57
  end
50
58
 
51
- def is_valid_url?(url)
52
- begin
53
- [URI::HTTP, URI::HTTPS].include?(URI.parse(url).class)
54
- rescue URI::InvalidURIError
55
- false
56
- end
59
+ def initialize(options)
60
+ load_options(options)
61
+ find_template_path
62
+ validate_options
63
+ provision
57
64
  end
58
-
59
65
  end
60
66
  end
@@ -1,3 +1,5 @@
1
+ # FIXME: Provisional::RailsApplication#initialize doesn't depend on instance state (Utility Function)
2
+
1
3
  require 'rails/version'
2
4
  require 'rails_generator'
3
5
  require 'rails_generator/scripts/generate'
@@ -0,0 +1,14 @@
1
+ ---
2
+ Duplication:
3
+ exclude:
4
+ - checkin
5
+ - generate_rails
6
+ - init
7
+
8
+ ControlCouple:
9
+ exclude:
10
+ - generate_rails
11
+
12
+ FeatureEnvy:
13
+ exclude:
14
+ - checkin
@@ -33,6 +33,12 @@ module Provisional
33
33
  repo
34
34
  end
35
35
  end
36
+
37
+ def provision
38
+ self.init
39
+ self.generate_rails
40
+ self.checkin
41
+ end
36
42
  end
37
43
  end
38
44
  end
@@ -1,5 +1,6 @@
1
1
  require 'provisional/scm/git'
2
2
  require 'net/http'
3
+ require 'net/https'
3
4
 
4
5
  module Provisional
5
6
  module SCM
@@ -9,11 +10,22 @@ module Provisional
9
10
  repo = super
10
11
  github_user = repo.config 'github.user'
11
12
  github_token = repo.config 'github.token'
12
- Net::HTTP.post_form URI.parse('https://github.com/api/v2/yaml/repos/create'), {
13
- 'login' => github_user,
14
- 'token' => github_token,
15
- 'name' => @options['name']
16
- }
13
+
14
+ connection = Net::HTTP.new('github.com', 443)
15
+ connection.use_ssl = true
16
+ connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
17
+
18
+ connection.start do |http|
19
+ req = Net::HTTP::Post.new("/api/v2/yaml/repos/create")
20
+ req.set_form_data(
21
+ 'login' => github_user,
22
+ 'token' => github_token,
23
+ 'name' => @options['name'],
24
+ 'public' => @options.keys.include?('private') ? 0 : 1
25
+ )
26
+ http.request(req)
27
+ end
28
+
17
29
  repo.add_remote('origin', "git@github.com:#{github_user}/#{@options['name']}.git")
18
30
  repo.push
19
31
  rescue
@@ -17,7 +17,7 @@ module Provisional
17
17
  system("svn co --username=#{@options['username']} --password=#{@options['password']} #{@options['url']} #{@options['name']}")
18
18
  Dir.chdir @options['name']
19
19
  if create_structure
20
- %w(branches tags trunk).each {|d| Dir.mkdir(d)}
20
+ %w(branches tags trunk).each {|directory| Dir.mkdir(directory)}
21
21
  system("svn add branches tags trunk")
22
22
  system("svn commit -m 'Structure by Provisional'")
23
23
  end
@@ -32,6 +32,12 @@ module Provisional
32
32
  system("svn commit -m 'Initial commit by Provisional'")
33
33
  end
34
34
  end
35
+
36
+ def provision
37
+ self.init
38
+ self.generate_rails
39
+ self.checkin
40
+ end
35
41
  end
36
42
  end
37
43
  end
@@ -0,0 +1,89 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{provisional}
5
+ s.version = "2.1.7"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Mark Cornick"]
9
+ s.date = %q{2009-06-04}
10
+ s.default_executable = %q{provisional}
11
+ s.description = %q{Provisional creates a new Rails project, using a standard Rails 2.3 application template, and checks it into a new SCM repository.}
12
+ s.email = %q{mark@viget.com}
13
+ s.executables = ["provisional"]
14
+ s.extra_rdoc_files = [
15
+ "README.md"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README.md",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "bin/provisional",
23
+ "lib/provisional.rb",
24
+ "lib/provisional/exceptions.reek",
25
+ "lib/provisional/project.rb",
26
+ "lib/provisional/rails_application.rb",
27
+ "lib/provisional/scm/beanstalk.rb",
28
+ "lib/provisional/scm/exceptions.reek",
29
+ "lib/provisional/scm/git.rb",
30
+ "lib/provisional/scm/github.rb",
31
+ "lib/provisional/scm/svn.rb",
32
+ "lib/provisional/scm/unfuddle.rb",
33
+ "lib/provisional/scm/unfuddle_svn.rb",
34
+ "lib/provisional/templates/viget.rb",
35
+ "lib/provisional/unfuddle_common.rb",
36
+ "provisional.gemspec",
37
+ "test/test_helper.rb",
38
+ "test/unit/beanstalk_test.rb",
39
+ "test/unit/git_test.rb",
40
+ "test/unit/github_test.rb",
41
+ "test/unit/project_test.rb",
42
+ "test/unit/rails_application_test.rb",
43
+ "test/unit/svn_test.rb",
44
+ "test/unit/unfuddle_common_test.rb",
45
+ "test/unit/unfuddle_svn_test.rb",
46
+ "test/unit/unfuddle_test.rb"
47
+ ]
48
+ s.has_rdoc = true
49
+ s.homepage = %q{http://github.com/vigetlabs/provisional}
50
+ s.rdoc_options = ["--charset=UTF-8"]
51
+ s.require_paths = ["lib"]
52
+ s.rubyforge_project = %q{viget}
53
+ s.rubygems_version = %q{1.3.2}
54
+ s.summary = %q{Automation for new Rails Projects}
55
+ s.test_files = [
56
+ "test/test_helper.rb",
57
+ "test/unit/beanstalk_test.rb",
58
+ "test/unit/git_test.rb",
59
+ "test/unit/github_test.rb",
60
+ "test/unit/project_test.rb",
61
+ "test/unit/rails_application_test.rb",
62
+ "test/unit/svn_test.rb",
63
+ "test/unit/unfuddle_common_test.rb",
64
+ "test/unit/unfuddle_svn_test.rb",
65
+ "test/unit/unfuddle_test.rb"
66
+ ]
67
+
68
+ if s.respond_to? :specification_version then
69
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
+ s.specification_version = 3
71
+
72
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
+ s.add_runtime_dependency(%q<trollop>, [">= 1.10.2"])
74
+ s.add_runtime_dependency(%q<rails>, [">= 2.3.0"])
75
+ s.add_runtime_dependency(%q<git>, [">= 1.0.5"])
76
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
77
+ else
78
+ s.add_dependency(%q<trollop>, [">= 1.10.2"])
79
+ s.add_dependency(%q<rails>, [">= 2.3.0"])
80
+ s.add_dependency(%q<git>, [">= 1.0.5"])
81
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<trollop>, [">= 1.10.2"])
85
+ s.add_dependency(%q<rails>, [">= 2.3.0"])
86
+ s.add_dependency(%q<git>, [">= 1.0.5"])
87
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
88
+ end
89
+ end
@@ -11,7 +11,7 @@ class BeanstalkTest < Test::Unit::TestCase
11
11
  @scm.init
12
12
  end
13
13
 
14
- def test_init_should_raise_RuntimeError_if_any_step_raises_any_exception
14
+ def test_init_should_fail_if_any_step_raises_any_exception
15
15
  Beanstalk::Repository.expects(:create).raises(Errno::ECONNREFUSED)
16
16
  assert_raise RuntimeError do
17
17
  @scm.init
@@ -14,7 +14,7 @@ class GitTest < Test::Unit::TestCase
14
14
  @scm.init
15
15
  end
16
16
 
17
- def test_init_should_raise_RuntimeError_if_any_step_raises_any_exception
17
+ def test_init_should_fail_if_any_step_raises_any_exception
18
18
  FileUtils.expects(:mkdir_p).with('name').raises(Errno::EEXIST)
19
19
  assert_raise RuntimeError do
20
20
  @scm.init
@@ -26,7 +26,7 @@ class GitTest < Test::Unit::TestCase
26
26
  @scm.generate_rails
27
27
  end
28
28
 
29
- def test_generate_rails_should_raise_RuntimeError_if_any_step_raises_any_exception
29
+ def test_generate_rails_should_fail_if_any_step_raises_any_exception
30
30
  Provisional::RailsApplication.expects(:new).raises(RuntimeError)
31
31
  assert_raise RuntimeError do
32
32
  @scm.generate_rails
@@ -38,10 +38,17 @@ class GitTest < Test::Unit::TestCase
38
38
  @scm.checkin
39
39
  end
40
40
 
41
- def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
41
+ def test_checkin_should_fail_if_any_step_raises_any_exception
42
42
  Git.expects(:open).raises(ArgumentError)
43
43
  assert_raise RuntimeError do
44
44
  @scm.checkin
45
45
  end
46
46
  end
47
+
48
+ def test_provision_should_call_init_generate_rails_and_checkin
49
+ @scm.expects(:init)
50
+ @scm.expects(:generate_rails)
51
+ @scm.expects(:checkin)
52
+ @scm.provision
53
+ end
47
54
  end
@@ -14,23 +14,38 @@ class GithubTest < Test::Unit::TestCase
14
14
  stub.expects(:push)
15
15
  end
16
16
 
17
- URI.expects(:parse).with('https://github.com/api/v2/yaml/repos/create')
18
- Net::HTTP.expects(:post_form).with(nil, { 'login' => 'user', 'token' => 'token', 'name' => 'name' })
17
+ stub_github do |stub|
18
+ stub.expects(:request).returns(true)
19
+ end
19
20
 
20
21
  @scm.checkin
21
22
  end
22
23
 
23
- def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
24
+ def test_checkin_should_fail_if_any_step_raises_any_exception
24
25
  stub_git_checkin do |stub|
25
26
  stub.expects(:config).with('github.user').returns('user')
26
27
  stub.expects(:config).with('github.token').returns('token')
27
28
  end
28
29
 
29
- URI.expects(:parse).with('https://github.com/api/v2/yaml/repos/create')
30
- Net::HTTP.expects(:post_form).with(nil, { 'login' => 'user', 'token' => 'token', 'name' => 'name' }).raises(Net::HTTPUnauthorized)
30
+ stub_github do |stub|
31
+ stub.expects(:request).raises(Net::HTTPUnauthorized)
32
+ end
31
33
 
32
34
  assert_raise RuntimeError do
33
35
  @scm.checkin
34
36
  end
35
37
  end
38
+
39
+ private
40
+
41
+ def stub_github
42
+ http = stub
43
+
44
+ connection = stub(:use_ssl= => true, :verify_mode= => true)
45
+ connection.expects(:start).yields(http)
46
+
47
+ Net::HTTP.expects(:new).with('github.com', 443).returns(connection)
48
+
49
+ yield http
50
+ end
36
51
  end
@@ -7,9 +7,7 @@ class ProjectTest < Test::Unit::TestCase
7
7
 
8
8
  def stub_git
9
9
  git_stub = stub()
10
- git_stub.expects(:init).returns('true')
11
- git_stub.expects(:generate_rails).returns('true')
12
- git_stub.expects(:checkin).returns('true')
10
+ git_stub.expects(:provision).returns('true')
13
11
  Provisional::SCM::Git.expects(:new).returns(git_stub)
14
12
  end
15
13
 
@@ -30,7 +30,7 @@ class SvnTest < Test::Unit::TestCase
30
30
  @scm.generate_rails(false)
31
31
  end
32
32
 
33
- def test_generate_rails_should_raise_RuntimeError_if_any_step_raises_any_exception
33
+ def test_generate_rails_should_fail_if_any_step_raises_any_exception
34
34
  @scm.expects(:system).with("svn co --username=username --password=password url name")
35
35
  Dir.expects(:chdir).with('name').raises(Errno::ENOENT)
36
36
  assert_raise RuntimeError do
@@ -44,10 +44,17 @@ class SvnTest < Test::Unit::TestCase
44
44
  @scm.checkin
45
45
  end
46
46
 
47
- def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
47
+ def test_checkin_should_fail_if_any_step_raises_any_exception
48
48
  @scm.expects(:system).with("svn add *").raises(RuntimeError)
49
49
  assert_raise RuntimeError do
50
50
  @scm.checkin
51
51
  end
52
52
  end
53
+
54
+ def test_provision_should_call_init_generate_rails_and_checkin
55
+ @scm.expects(:init)
56
+ @scm.expects(:generate_rails)
57
+ @scm.expects(:checkin)
58
+ @scm.provision
59
+ end
53
60
  end
@@ -38,7 +38,7 @@ class UnfuddleCommonTest < Test::Unit::TestCase
38
38
  create_repository(options)
39
39
  end
40
40
 
41
- def test_checkin_should_raise_RuntimeError_if_unfuddle_api_call_fails
41
+ def test_checkin_should_fail_if_unfuddle_api_call_fails
42
42
  options = {'username' => 'username', 'password' => 'password', 'domain' => 'domain'}
43
43
  request_stub = stub()
44
44
  request_stub.expects(:basic_auth).with('username', 'password')
@@ -57,7 +57,7 @@ class UnfuddleCommonTest < Test::Unit::TestCase
57
57
  end
58
58
  end
59
59
 
60
- def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
60
+ def test_checkin_should_fail_if_any_step_raises_any_exception
61
61
  options = {'domain' => 'domain'}
62
62
  Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).raises(Net::HTTPNotFound)
63
63
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vigetlabs-provisional
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cornick
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-26 00:00:00 -07:00
12
+ date: 2009-06-04 00:00:00 -07:00
13
13
  default_executable: provisional
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,14 +61,17 @@ extensions: []
61
61
  extra_rdoc_files:
62
62
  - README.md
63
63
  files:
64
+ - .gitignore
64
65
  - README.md
65
66
  - Rakefile
66
67
  - VERSION.yml
67
68
  - bin/provisional
68
69
  - lib/provisional.rb
70
+ - lib/provisional/exceptions.reek
69
71
  - lib/provisional/project.rb
70
72
  - lib/provisional/rails_application.rb
71
73
  - lib/provisional/scm/beanstalk.rb
74
+ - lib/provisional/scm/exceptions.reek
72
75
  - lib/provisional/scm/git.rb
73
76
  - lib/provisional/scm/github.rb
74
77
  - lib/provisional/scm/svn.rb
@@ -76,6 +79,7 @@ files:
76
79
  - lib/provisional/scm/unfuddle_svn.rb
77
80
  - lib/provisional/templates/viget.rb
78
81
  - lib/provisional/unfuddle_common.rb
82
+ - provisional.gemspec
79
83
  - test/test_helper.rb
80
84
  - test/unit/beanstalk_test.rb
81
85
  - test/unit/git_test.rb