Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#53] Add --github option to create a github repo

  • Loading branch information...
commit cd3317bec23eba0cb6a86e12c150a0bb7cf339db 1 parent 826c856
Dan Croak croaky authored
2  Gemfile.lock
View
@@ -3,6 +3,7 @@ PATH
specs:
suspenders (1.0.1)
bundler (>= 1.1)
+ hub (~> 1.10.2)
rails (= 3.2.6)
GEM
@@ -56,6 +57,7 @@ GEM
gherkin (2.9.3)
json (>= 1.4.6)
hike (1.2.1)
+ hub (1.10.2)
i18n (0.6.0)
journey (1.0.4)
json (1.6.6)
11 README.md
View
@@ -63,6 +63,17 @@ This has the same effect as running:
heroku create app-staging --remote staging
heroku create app-production --remote production
+Github
+------
+
+You can optionally create a Github repository:
+
+ suspenders app --github organization/project
+
+This has the same effect as running:
+
+ hub create organization/project
+
Clearance
---------
8 features/github_repo.feature
View
@@ -0,0 +1,8 @@
+@disable-bundler
+Feature: Creating a Github repo
+
+ Scenario: --github=organization/project
+ When I suspend a project called "test_project" with:
+ | argument | value |
+ | --github | organization/project |
+ Then the "organization/project" Github repo should exist
4 features/heroku_true.feature
View
@@ -5,5 +5,5 @@ Feature: Creating a Heroku app
When I suspend a project called "test_project" with:
| argument | value |
| --heroku | true |
- Then the "test_project-staging" heroku app should exist
- And the "test_project-production" heroku app should exist
+ Then the "test_project-staging" Heroku app should exist
+ And the "test_project-production" Heroku app should exist
6 features/step_definitions/suspenders_steps.rb
View
@@ -64,6 +64,10 @@
check_file_content file_path, content, false
end
-Then /^the "([^"]*)" heroku app should exist$/ do |app_name|
+Then /^the "([^"]*)" Heroku app should exist$/ do |app_name|
FakeHeroku.should have_created_app(app_name)
end
+
+Then /^the "([^"]*)" Github repo should exist$/ do |repo_name|
+ FakeGithub.should have_created_repo(repo_name)
+end
9 features/support/env.rb
View
@@ -1,15 +1,10 @@
Before do
ENV['TESTING'] = 'true'
-end
-
-Before do
@aruba_timeout_seconds = 560
end
After do
FakeHeroku.clear!
-end
-
-After do
- FileUtils.rm_rf('test_project')
+ FakeGithub.clear!
+ FileUtils.rm_rf 'test_project'
end
21 features/support/fake_github.rb
View
@@ -0,0 +1,21 @@
+class FakeGithub
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'hub_commands'), File.dirname(__FILE__))
+
+ def initialize(args)
+ @args = args
+ end
+
+ def run!
+ File.open(RECORDER, 'a') do |file|
+ file.write @args.join(' ')
+ end
+ end
+
+ def self.clear!
+ FileUtils.rm_rf RECORDER
+ end
+
+ def self.has_created_repo?(repo_name)
+ File.open(RECORDER, 'r').read.include?("create #{repo_name}")
+ end
+end
2  features/support/fake_heroku.rb
View
@@ -12,7 +12,7 @@ def run!
end
def self.clear!
- FileUtils.rm_rf(RECORDER)
+ FileUtils.rm_rf RECORDER
end
def self.has_created_app?(app_name)
20 lib/suspenders/app_builder.rb
View
@@ -162,11 +162,7 @@ def init_git
end
def create_heroku_apps
- path_additions = ''
- if ENV['TESTING']
- support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
- path_addition = "PATH=#{support_bin}:$PATH"
- end
+ path_addition = override_path_for_tests
run "#{path_addition} heroku create #{app_name}-production --remote=production"
run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
end
@@ -177,6 +173,11 @@ def document_heroku
inject_into_file('README.md', "#{documentation}\n", :before => 'Most importantly')
end
+ def create_github_repo(repo_name)
+ path_addition = override_path_for_tests
+ run "#{path_addition} hub create #{repo_name}"
+ end
+
def copy_miscellaneous_files
copy_file 'errors.rb', 'config/initializers/errors.rb'
copy_file 'time_formats.rb', 'config/initializers/time_formats.rb'
@@ -225,5 +226,14 @@ def setup_default_rake_task
'task(:default).clear\ntask :default => [:spec, :cucumber]'
end
end
+
+ private
+
+ def override_path_for_tests
+ if ENV['TESTING']
+ support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
+ "PATH=#{support_bin}:$PATH"
+ end
+ end
end
end
17 lib/suspenders/generators/app_generator.rb
View
@@ -10,7 +10,10 @@ class AppGenerator < Rails::Generators::AppGenerator
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
class_option :heroku, :type => :boolean, :aliases => '-H', :default => false,
- :desc => 'Create staging and production heroku apps'
+ :desc => 'Create staging and production Heroku apps'
+
+ class_option :github, :type => :string, :aliases => '-G', :default => nil,
+ :desc => 'Create Github repository and add remote origin pointed to repo'
class_option :skip_test_unit, :type => :boolean, :aliases => '-T', :default => true,
:desc => 'Skip Test::Unit files'
@@ -40,6 +43,7 @@ def suspenders_customization
invoke :setup_root_route
invoke :setup_git
invoke :create_heroku_apps
+ invoke :create_github_repo
invoke :outro
end
@@ -136,13 +140,20 @@ def setup_git
end
def create_heroku_apps
- if options['heroku']
- say 'Creating heroku apps'
+ if options[:heroku]
+ say 'Creating Heroku apps'
build :create_heroku_apps
build :document_heroku
end
end
+ def create_github_repo
+ if options[:github]
+ say 'Creating Github repo'
+ build :create_github_repo, options[:github]
+ end
+ end
+
def setup_gitignore
build :gitignore_files
end
9 suspenders.gemspec
View
@@ -27,9 +27,10 @@ rush to build something amazing; don't use it if you like missing deadlines.
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md LICENSE]
- s.add_dependency('rails', '3.2.6')
- s.add_dependency('bundler', '>= 1.1')
+ s.add_dependency 'rails', '3.2.6'
+ s.add_dependency 'bundler', '>= 1.1'
+ s.add_dependency 'hub', '~> 1.10.2'
- s.add_development_dependency('cucumber', '~> 1.1.9')
- s.add_development_dependency('aruba', '~> 0.4.11')
+ s.add_development_dependency 'cucumber', '~> 1.1.9'
+ s.add_development_dependency 'aruba', '~> 0.4.11'
end
Please sign in to comment.
Something went wrong with that request. Please try again.