Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Optional github integration (--[no-]github support) #186

Open
wants to merge 2 commits into from

2 participants

Rene Lengwinat Josh Nichols
Rene Lengwinat

This patch allows the user to create a jeweler project structure without having any git(+hub) integration. I've added the option in a way the tool still behaves in the original way and tries to add fully github support, so it should provide full backward compatibility.

To disable github support the user just has to apply the --no-github option.

Josh Nichols

Very nice. There's been a long standing request open for support for not using git/github, and this definitely is a step towards that.

I'll review & merge this soon (hopefully). One thing to consider would be how to document this in a way that folks can find it. If you can think of anything, by all means let me know!

Rene Lengwinat

Readme file? Do you have release blog in jeweler?

Changing the current behavior to disable github support by default would be dramatic step but considerable for a further major release.

Josh Nichols

user_email and user_name are used in the Rakefile, so they would need to be present. A couple of options:

  • Update the exception to be NoUserName and NoUserEmail and update language in Jeweler::Generator::Application to reflect this
  • Fill in a default value if they aren't present. This is done for some other fields already, so may be legit.
Josh Nichols

I'm a little torn on this flag. Some of the pieces it turns on are really any and all git, not just github. Possibly split up to --no-git and --no-github? --no-git could then imply --no-github.

Josh Nichols

Had a chance to look at this more closely, and it's actually reallllly close to being everything needed for non-git support. I've left some in line comments on the commits.

The only major consideration I can think of would be the impact of not having a git repository around when using the rake tasks. I'm not positive if they assume it's there or not, but it should be straightforward to only conditionally do some things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
31 lib/jeweler/generator.rb
View
@@ -47,9 +47,9 @@ class Generator
attr_accessor :target_dir, :user_name, :user_email, :summary, :homepage,
:description, :project_name, :github_username, :github_token,
- :repo, :should_create_remote_repo,
+ :repo, :should_create_remote_repo,
:testing_framework, :documentation_framework,
- :should_use_cucumber, :should_use_bundler,
+ :should_use_cucumber, :should_use_bundler, :should_use_github,
:should_setup_rubyforge, :should_use_reek, :should_use_roodi,
:development_dependencies,
:options,
@@ -57,10 +57,18 @@ class Generator
def initialize(options = {})
self.options = options
+ extracted_directory = nil
self.project_name = options[:project_name]
if self.project_name.nil? || self.project_name.squeeze.strip == ""
raise NoGitHubRepoNameGiven
+ else
+ path = File.split(self.project_name)
+
+ if path.size > 1
+ extracted_directory = File.join(path[0..-1])
+ self.project_name = path.last
+ end
end
self.development_dependencies = []
@@ -82,7 +90,7 @@ def initialize(options = {})
raise ArgumentError, "Unsupported documentation framework (#{documentation_framework})"
end
- self.target_dir = options[:directory] || self.project_name
+ self.target_dir = options[:directory] || extracted_directory || self.project_name
self.summary = options[:summary] || 'TODO: one-line summary of your gem'
self.description = options[:description] || 'TODO: longer description of your gem'
@@ -92,6 +100,9 @@ def initialize(options = {})
self.should_setup_rubyforge = options[:rubyforge]
self.should_use_bundler = options[:use_bundler]
+ self.should_use_github = true
+ self.should_use_github = options[:use_github] if options.has_key?(:use_github)
+
development_dependencies << ["cucumber", ">= 0"] if should_use_cucumber
# TODO make bundler optional?
@@ -108,17 +119,19 @@ def initialize(options = {})
self.git_remote = options[:git_remote]
- raise NoGitUserName unless self.user_name
- raise NoGitUserEmail unless self.user_email
+ if self.should_use_github
+ raise NoGitUserName unless self.user_name
+ raise NoGitUserEmail unless self.user_email
- extend GithubMixin
+ extend GithubMixin
+ end
end
def run
create_files
- create_version_control
+ create_version_control if self.should_use_github
$stdout.puts "Jeweler has prepared your gem in #{target_dir}"
- if should_create_remote_repo
+ if self.should_create_remote_repo
create_and_push_repo
$stdout.puts "Jeweler has pushed your repo to #{homepage}"
end
@@ -174,7 +187,7 @@ def create_files
end
- output_template_in_target '.gitignore'
+ output_template_in_target '.gitignore' if should_use_github
output_template_in_target 'Rakefile'
output_template_in_target 'Gemfile' if should_use_bundler
output_template_in_target 'LICENSE.txt'
6 lib/jeweler/generator/options.rb
View
@@ -10,6 +10,8 @@ def initialize(args)
self[:testing_framework] = :shoulda
self[:documentation_framework] = :rdoc
self[:use_bundler] = true
+ self[:use_github] = true
+ self[:create_repo] = false
git_config = if Pathname.new("~/.gitconfig").expand_path.exist?
Git.global_config
@@ -73,6 +75,10 @@ def initialize(args)
self[:use_bundler] = v
end
+ o.on('--[no-]github', 'prepare project for github integration') do |v|
+ self[:use_github] = v
+ end
+
o.on('--cucumber', 'generate cucumber stories in addition to the other tests') do
self[:use_cucumber] = true
end
26 test/jeweler/test_generator.rb
View
@@ -2,12 +2,14 @@
class TestGenerator < Test::Unit::TestCase
def build_generator(testing_framework = :shoulda, options = {})
- options = options.merge :project_name => 'the-perfect-gem',
- :user_name => 'John Doe',
- :user_email => 'john@example.com',
- :github_username => 'johndoe',
- :github_token => 'yyz',
- :documentation_framework => :rdoc
+ options = {
+ :project_name => 'the-perfect-gem',
+ :user_name => 'John Doe',
+ :user_email => 'john@example.com',
+ :github_username => 'johndoe',
+ :github_token => 'yyz',
+ :documentation_framework => :rdoc
+ }.merge(options)
options[:testing_framework] = testing_framework
Jeweler::Generator.new(options)
@@ -34,6 +36,18 @@ def build_generator(testing_framework = :shoulda, options = {})
assert_equal 'git@github.com:johndoe/the-perfect-gem.git', build_generator.git_remote
end
+ should "extract project name from absolut path" do
+ assert_equal "my-project", build_generator(:shoulda, {:project_name => "/tmp/my-project"}).project_name
+ end
+
+ should "extract project name from relative path" do
+ assert_equal "my-project", build_generator(:shoulda, {:project_name => "../my-project"}).project_name
+ end
+
+ should "extract project name from direct path" do
+ assert_equal "my-project", build_generator(:shoulda, {:project_name => "my-project"}).project_name
+ end
+
def self.should_have_generator_attribute(attribute, value)
should "have #{value} for #{attribute}" do
assert_equal value, build_generator(@framework).send(attribute)
16 test/jeweler/test_generator_initialization.rb
View
@@ -101,7 +101,7 @@ def build_generator(options = {})
end
should "set target directory to the project name" do
- assert_equal @project_name, @generator.target_dir
+ assert_equal @project_name, File.split(@generator.target_dir).last
end
should "set user's name from git config" do
@@ -161,4 +161,18 @@ def build_generator(options = {})
end
+ context "disabling github integration" do
+ setup do
+ @generator = build_generator(:use_github => false)
+ stub_git_config
+ end
+
+ should "not set git_remote" do
+ assert_nil @generator.git_remote
+ end
+
+ should "not fail on getting git username" do
+ build_generator(:use_github => false, :github_username => nil)
+ end
+ end
end
Something went wrong with that request. Please try again.