dima-jeweler 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.markdown +58 -0
- data/LICENSE +20 -0
- data/README.markdown +103 -0
- data/Rakefile +61 -0
- data/TODO +11 -0
- data/VERSION.yml +4 -0
- data/bin/jeweler +8 -0
- data/lib/jeweler.rb +161 -0
- data/lib/jeweler/commands.rb +11 -0
- data/lib/jeweler/commands/build_gem.rb +22 -0
- data/lib/jeweler/commands/install_gem.rb +19 -0
- data/lib/jeweler/commands/release.rb +46 -0
- data/lib/jeweler/commands/release_to_rubyforge.rb +28 -0
- data/lib/jeweler/commands/validate_gemspec.rb +21 -0
- data/lib/jeweler/commands/version/base.rb +30 -0
- data/lib/jeweler/commands/version/bump_major.rb +13 -0
- data/lib/jeweler/commands/version/bump_minor.rb +12 -0
- data/lib/jeweler/commands/version/bump_patch.rb +14 -0
- data/lib/jeweler/commands/version/write.rb +12 -0
- data/lib/jeweler/commands/write_gemspec.rb +26 -0
- data/lib/jeweler/errors.rb +8 -0
- data/lib/jeweler/gemspec_helper.rb +51 -0
- data/lib/jeweler/generator.rb +345 -0
- data/lib/jeweler/generator/application.rb +45 -0
- data/lib/jeweler/generator/options.rb +64 -0
- data/lib/jeweler/tasks.rb +102 -0
- data/lib/jeweler/templates/.gitignore +5 -0
- data/lib/jeweler/templates/LICENSE +20 -0
- data/lib/jeweler/templates/README.rdoc +7 -0
- data/lib/jeweler/templates/Rakefile +116 -0
- data/lib/jeweler/templates/bacon/flunking.rb +7 -0
- data/lib/jeweler/templates/bacon/helper.rb +8 -0
- data/lib/jeweler/templates/features/default.feature +9 -0
- data/lib/jeweler/templates/features/support/env.rb +11 -0
- data/lib/jeweler/templates/micronaut/flunking.rb +7 -0
- data/lib/jeweler/templates/micronaut/helper.rb +17 -0
- data/lib/jeweler/templates/minitest/flunking.rb +7 -0
- data/lib/jeweler/templates/minitest/helper.rb +11 -0
- data/lib/jeweler/templates/rspec/flunking.rb +7 -0
- data/lib/jeweler/templates/rspec/helper.rb +9 -0
- data/lib/jeweler/templates/shoulda/flunking.rb +7 -0
- data/lib/jeweler/templates/shoulda/helper.rb +10 -0
- data/lib/jeweler/templates/testunit/flunking.rb +7 -0
- data/lib/jeweler/templates/testunit/helper.rb +9 -0
- data/lib/jeweler/version_helper.rb +83 -0
- data/test/fixtures/bar/VERSION.yml +4 -0
- data/test/geminstaller.yml +12 -0
- data/test/generators/initialization_test.rb +146 -0
- data/test/jeweler/commands/test_build_gem.rb +53 -0
- data/test/jeweler/commands/test_install_gem.rb +0 -0
- data/test/jeweler/commands/test_release.rb +150 -0
- data/test/jeweler/commands/test_release_to_rubyforge.rb +141 -0
- data/test/jeweler/commands/test_write_gemspec.rb +58 -0
- data/test/jeweler/commands/version/test_bump_major.rb +21 -0
- data/test/jeweler/commands/version/test_bump_minor.rb +19 -0
- data/test/jeweler/commands/version/test_bump_patch.rb +20 -0
- data/test/jeweler/commands/version/test_write.rb +23 -0
- data/test/shoulda_macros/jeweler_macros.rb +35 -0
- data/test/test_application.rb +109 -0
- data/test/test_gemspec_helper.rb +36 -0
- data/test/test_generator.rb +179 -0
- data/test/test_helper.rb +51 -0
- data/test/test_jeweler.rb +136 -0
- data/test/test_options.rb +90 -0
- data/test/test_tasks.rb +40 -0
- data/test/test_version_helper.rb +115 -0
- metadata +152 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
class BuildGem
|
4
|
+
attr_accessor :base_dir, :gemspec_helper, :file_utils
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.file_utils = FileUtils
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
gemspec = gemspec_helper.parse
|
12
|
+
gem_file_name = Gem::Builder.new(gemspec).build
|
13
|
+
|
14
|
+
pkg_dir = File.join(base_dir, 'pkg')
|
15
|
+
file_utils.mkdir_p pkg_dir
|
16
|
+
|
17
|
+
gem_file_name = File.join(base_dir, gem_file_name)
|
18
|
+
file_utils.mv gem_file_name, pkg_dir
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
class InstallGem
|
4
|
+
attr_accessor :gemspec_helper, :output
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.output = $stdout
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def run
|
12
|
+
command = "sudo gem install #{gemspec_helper.gem_path}"
|
13
|
+
output.puts "Executing #{command.inspect}:"
|
14
|
+
|
15
|
+
sh command # TODO where does sh actually come from!?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
class Release
|
4
|
+
attr_accessor :gemspec, :version, :repo, :output, :gemspec_helper, :base_dir
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.output = $stdout
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
repo.checkout('master')
|
12
|
+
|
13
|
+
raise "Hey buddy, try committing them files first" if any_pending_changes?
|
14
|
+
|
15
|
+
gemspec_helper.update_version(version)
|
16
|
+
gemspec_helper.write
|
17
|
+
|
18
|
+
repo.add(gemspec_helper.path)
|
19
|
+
output.puts "Committing #{gemspec_helper.path}"
|
20
|
+
repo.commit("Regenerated gemspec for version #{version}")
|
21
|
+
|
22
|
+
output.puts "Pushing master to origin"
|
23
|
+
repo.push
|
24
|
+
|
25
|
+
output.puts "Tagging #{release_tag}"
|
26
|
+
repo.add_tag(release_tag)
|
27
|
+
|
28
|
+
output.puts "Pushing #{release_tag} to origin"
|
29
|
+
repo.push('origin', release_tag)
|
30
|
+
end
|
31
|
+
|
32
|
+
def any_pending_changes?
|
33
|
+
!(@repo.status.added.empty? && @repo.status.deleted.empty? && @repo.status.changed.empty?)
|
34
|
+
end
|
35
|
+
|
36
|
+
def release_tag
|
37
|
+
"v#{version}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemspec_helper
|
41
|
+
@gemspec_helper ||= Jeweler::GemSpecHelper.new(self.gemspec, self.base_dir)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubyforge'
|
2
|
+
|
3
|
+
class Jeweler
|
4
|
+
module Commands
|
5
|
+
class ReleaseToRubyforge
|
6
|
+
attr_accessor :gemspec, :version, :repo, :output, :gemspec_helper, :ruby_forge
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.output = $stdout
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
raise "rubyforge_project not configured. Add this to the Jeweler::Tasks block in your Rakefile." if @gemspec.rubyforge_project.nil?
|
14
|
+
|
15
|
+
@ruby_forge.configure rescue nil
|
16
|
+
output.puts 'Logging in'
|
17
|
+
@ruby_forge.login
|
18
|
+
|
19
|
+
@ruby_forge.userconfig['release_notes'] = @gemspec.description if @gemspec.description
|
20
|
+
@ruby_forge.userconfig['preformatted'] = true
|
21
|
+
|
22
|
+
output.puts "Releasing #{@gemspec.name} v. #{@version} as #{@gemspec.rubyforge_project}"
|
23
|
+
@ruby_forge.add_release(@gemspec.rubyforge_project, @gemspec.name, @version.to_s, @gemspec_helper.gem_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
class ValidateGemspec
|
4
|
+
attr_accessor :gemspec_helper, :output
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.output = $stdout
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
begin
|
12
|
+
gemspec_helper.parse
|
13
|
+
output.puts "#{gemspec_helper.path} is valid."
|
14
|
+
rescue Exception => e
|
15
|
+
output.puts "#{gemspec_helper.path} is invalid. See the backtrace for more details."
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
module Version
|
4
|
+
class Base
|
5
|
+
|
6
|
+
attr_accessor :repo, :version_helper, :gemspec, :commit
|
7
|
+
|
8
|
+
def run
|
9
|
+
update_version
|
10
|
+
|
11
|
+
self.version_helper.write
|
12
|
+
self.gemspec.version = self.version_helper.to_s
|
13
|
+
|
14
|
+
commit_version if self.repo && self.commit
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_version
|
18
|
+
raise "Subclasses should implement this"
|
19
|
+
end
|
20
|
+
|
21
|
+
def commit_version
|
22
|
+
if self.repo
|
23
|
+
self.repo.add('VERSION.yml')
|
24
|
+
self.repo.commit("Version bump to #{self.version_helper.to_s}", 'VERSION.yml')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
class WriteGemspec
|
4
|
+
attr_accessor :base_dir, :gemspec, :version, :output, :gemspec_helper, :version_helper
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.output = $stdout
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
version_helper.refresh
|
12
|
+
gemspec_helper.spec.version = version_helper.to_s
|
13
|
+
gemspec_helper.spec.date = Time.now
|
14
|
+
|
15
|
+
gemspec_helper.write
|
16
|
+
|
17
|
+
output.puts "Generated: #{gemspec_helper.path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def gemspec_helper
|
21
|
+
@gemspec_helper ||= GemSpecHelper.new(self.gemspec, self.base_dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Jeweler
|
2
|
+
|
3
|
+
class GemSpecHelper
|
4
|
+
|
5
|
+
attr_accessor :spec, :base_dir
|
6
|
+
|
7
|
+
def initialize(spec, base_dir = nil)
|
8
|
+
self.spec = spec
|
9
|
+
self.base_dir = base_dir || ''
|
10
|
+
|
11
|
+
yield spec if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
begin
|
16
|
+
parse
|
17
|
+
true
|
18
|
+
rescue
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def write
|
24
|
+
File.open(path, 'w') do |f|
|
25
|
+
f.write @spec.to_ruby
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def path
|
30
|
+
denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec")
|
31
|
+
absolute_path = File.expand_path(denormalized_path)
|
32
|
+
absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse
|
36
|
+
data = File.read(path)
|
37
|
+
parsed_gemspec = nil
|
38
|
+
Thread.new { parsed_gemspec = eval("$SAFE = 3\n#{data}", binding, path) }.join
|
39
|
+
parsed_gemspec
|
40
|
+
end
|
41
|
+
|
42
|
+
def gem_path
|
43
|
+
File.join(@base_dir, 'pkg', parse.file_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_version(version)
|
47
|
+
@spec.version = version.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,345 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
class Jeweler
|
8
|
+
class NoGitUserName < StandardError
|
9
|
+
end
|
10
|
+
class NoGitUserEmail < StandardError
|
11
|
+
end
|
12
|
+
class FileInTheWay < StandardError
|
13
|
+
end
|
14
|
+
class NoGitHubRepoNameGiven < StandardError
|
15
|
+
end
|
16
|
+
class NoGitHubUser < StandardError
|
17
|
+
end
|
18
|
+
class NoGitHubToken < StandardError
|
19
|
+
end
|
20
|
+
class GitInitFailed < StandardError
|
21
|
+
end
|
22
|
+
|
23
|
+
class Generator
|
24
|
+
attr_accessor :target_dir, :user_name, :user_email, :summary, :testing_framework,
|
25
|
+
:github_repo_name, :github_username, :github_token,
|
26
|
+
:repo, :should_create_repo, :should_use_cucumber
|
27
|
+
|
28
|
+
SUPPORTED_TESTING_FRAMEWORKS = [:shoulda, :testunit, :bacon, :rspec, :micronaut, :minitest]
|
29
|
+
|
30
|
+
def initialize(github_repo_name, options = {})
|
31
|
+
if github_repo_name.nil? || github_repo_name.squeeze.strip == ""
|
32
|
+
raise NoGitHubRepoNameGiven
|
33
|
+
end
|
34
|
+
|
35
|
+
self.github_repo_name = github_repo_name
|
36
|
+
|
37
|
+
self.testing_framework = (options[:testing_framework] || :shoulda).to_sym
|
38
|
+
unless SUPPORTED_TESTING_FRAMEWORKS.include? self.testing_framework
|
39
|
+
raise ArgumentError, "Unsupported testing framework (#{testing_framework})"
|
40
|
+
end
|
41
|
+
|
42
|
+
self.target_dir = options[:directory] || self.github_repo_name
|
43
|
+
|
44
|
+
self.should_create_repo = options[:create_repo]
|
45
|
+
self.summary = options[:summary] || 'TODO'
|
46
|
+
self.should_use_cucumber= options[:use_cucumber]
|
47
|
+
|
48
|
+
use_user_git_config
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def run
|
53
|
+
create_files
|
54
|
+
gitify
|
55
|
+
$stdout.puts "Jeweler has prepared your gem in #{github_repo_name}"
|
56
|
+
if should_create_repo
|
57
|
+
create_and_push_repo
|
58
|
+
$stdout.puts "Jeweler has pushed your repo to #{github_url}"
|
59
|
+
enable_gem_for_repo
|
60
|
+
$stdout.puts "Jeweler has enabled gem building for your repo"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Directory where 'tests' live
|
65
|
+
def test_dir
|
66
|
+
test_or_spec
|
67
|
+
end
|
68
|
+
|
69
|
+
# Default rake task to use
|
70
|
+
def default_task
|
71
|
+
case testing_framework.to_sym
|
72
|
+
when :shoulda, :testunit, :minitest
|
73
|
+
'test'
|
74
|
+
when :bacon, :rspec
|
75
|
+
'spec'
|
76
|
+
when :micronaut
|
77
|
+
'examples'
|
78
|
+
else
|
79
|
+
raise ArgumentError, "Don't know default task for #{testing_framework}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def feature_support_require
|
84
|
+
case testing_framework.to_sym
|
85
|
+
when :testunit, :shoulda, :bacon # NOTE bacon doesn't really work inside of cucumber
|
86
|
+
'test/unit/assertions'
|
87
|
+
when :minitest
|
88
|
+
'mini/test'
|
89
|
+
when :rspec
|
90
|
+
'spec/expectations'
|
91
|
+
when :micronaut
|
92
|
+
'micronaut/expectations'
|
93
|
+
else
|
94
|
+
raise "Don't know what to require for #{testing_framework}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def feature_support_extend
|
99
|
+
case testing_framework.to_sym
|
100
|
+
when :testunit, :shoulda, :bacon # NOTE bacon doesn't really work inside of cucumber
|
101
|
+
'Test::Unit::Assertions'
|
102
|
+
when :minitest
|
103
|
+
'Mini::Test::Assertions'
|
104
|
+
when :rspec
|
105
|
+
nil
|
106
|
+
when :micronaut
|
107
|
+
'Micronaut::Matchers'
|
108
|
+
else
|
109
|
+
raise "Don't know what to extend for #{testing_framework}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def github_remote
|
114
|
+
"git@github.com:#{github_username}/#{github_repo_name}.git"
|
115
|
+
end
|
116
|
+
|
117
|
+
def github_url
|
118
|
+
"http://github.com/#{github_username}/#{github_repo_name}"
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def constant_name
|
123
|
+
self.github_repo_name.split(/[-_]/).collect{|each| each.capitalize }.join
|
124
|
+
end
|
125
|
+
|
126
|
+
def file_name_prefix
|
127
|
+
self.github_repo_name.gsub('-', '_')
|
128
|
+
end
|
129
|
+
|
130
|
+
def lib_dir
|
131
|
+
'lib'
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_dir
|
135
|
+
case testing_framework.to_sym
|
136
|
+
when :shoulda, :testunit, :minitest
|
137
|
+
'test'
|
138
|
+
when :bacon, :rspec
|
139
|
+
'spec'
|
140
|
+
when :micronaut
|
141
|
+
'examples'
|
142
|
+
else
|
143
|
+
raise ArgumentError, "Don't know test dir for #{testing_framework.inspect}"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_filename
|
148
|
+
"#{file_name_prefix}_#{test_or_spec}.rb"
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_helper_filename
|
152
|
+
"#{test_or_spec}_helper.rb"
|
153
|
+
end
|
154
|
+
|
155
|
+
def feature_filename
|
156
|
+
"#{file_name_prefix}.feature"
|
157
|
+
end
|
158
|
+
|
159
|
+
def steps_filename
|
160
|
+
"#{file_name_prefix}_steps.rb"
|
161
|
+
end
|
162
|
+
|
163
|
+
def features_dir
|
164
|
+
'features'
|
165
|
+
end
|
166
|
+
|
167
|
+
def features_support_dir
|
168
|
+
File.join(features_dir, 'support')
|
169
|
+
end
|
170
|
+
|
171
|
+
def features_steps_dir
|
172
|
+
File.join(features_dir, 'step_definitions')
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_or_spec
|
176
|
+
case testing_framework.to_sym
|
177
|
+
when :shoulda, :testunit, :minitest
|
178
|
+
'test'
|
179
|
+
when :bacon, :rspec
|
180
|
+
'spec'
|
181
|
+
when :micronaut
|
182
|
+
'example'
|
183
|
+
else
|
184
|
+
raise ArgumentError, "Unknown test style: #{testing_framework}"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
protected
|
190
|
+
|
191
|
+
# This is in a separate method so we can stub it out during testing
|
192
|
+
def read_git_config
|
193
|
+
# we could just use Git::Base's .config, but that relies on a repo being around already
|
194
|
+
# ... which we don't have yet, since this is part of a sanity check
|
195
|
+
lib = Git::Lib.new(nil, nil)
|
196
|
+
config = lib.parse_config '~/.gitconfig'
|
197
|
+
end
|
198
|
+
|
199
|
+
private
|
200
|
+
def create_files
|
201
|
+
unless File.exists?(target_dir) || File.directory?(target_dir)
|
202
|
+
FileUtils.mkdir target_dir
|
203
|
+
else
|
204
|
+
raise FileInTheWay, "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?"
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
output_template_in_target '.gitignore'
|
209
|
+
output_template_in_target 'Rakefile'
|
210
|
+
output_template_in_target 'LICENSE'
|
211
|
+
output_template_in_target 'README.rdoc'
|
212
|
+
|
213
|
+
mkdir_in_target lib_dir
|
214
|
+
touch_in_target File.join(lib_dir, "#{file_name_prefix}.rb")
|
215
|
+
|
216
|
+
mkdir_in_target test_dir
|
217
|
+
output_template_in_target File.join(testing_framework.to_s, 'helper.rb'), File.join(test_dir, test_helper_filename)
|
218
|
+
output_template_in_target File.join(testing_framework.to_s, 'flunking.rb'), File.join(test_dir, test_filename)
|
219
|
+
|
220
|
+
if should_use_cucumber
|
221
|
+
mkdir_in_target features_dir
|
222
|
+
output_template_in_target File.join(%w(features default.feature)), File.join('features', feature_filename)
|
223
|
+
|
224
|
+
mkdir_in_target features_support_dir
|
225
|
+
output_template_in_target File.join(features_support_dir, 'env.rb')
|
226
|
+
|
227
|
+
mkdir_in_target features_steps_dir
|
228
|
+
touch_in_target File.join(features_steps_dir, steps_filename)
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
def use_user_git_config
|
234
|
+
git_config = self.read_git_config
|
235
|
+
|
236
|
+
unless git_config.has_key? 'user.name'
|
237
|
+
raise NoGitUserName
|
238
|
+
end
|
239
|
+
|
240
|
+
unless git_config.has_key? 'user.email'
|
241
|
+
raise NoGitUserEmail
|
242
|
+
end
|
243
|
+
|
244
|
+
unless git_config.has_key? 'github.user'
|
245
|
+
raise NoGitHubUser
|
246
|
+
end
|
247
|
+
|
248
|
+
unless git_config.has_key? 'github.token'
|
249
|
+
raise NoGitHubToken
|
250
|
+
end
|
251
|
+
|
252
|
+
self.user_name = git_config['user.name']
|
253
|
+
self.user_email = git_config['user.email']
|
254
|
+
self.github_username = git_config['github.user']
|
255
|
+
self.github_token = git_config['github.token']
|
256
|
+
end
|
257
|
+
|
258
|
+
def output_template_in_target(source, destination = source)
|
259
|
+
final_destination = File.join(target_dir, destination)
|
260
|
+
|
261
|
+
template_contents = File.read(File.join(template_dir, source))
|
262
|
+
template = ERB.new(template_contents, nil, '<>')
|
263
|
+
|
264
|
+
template_result = template.result(binding)
|
265
|
+
|
266
|
+
File.open(final_destination, 'w') {|file| file.write(template_result)}
|
267
|
+
|
268
|
+
$stdout.puts "\tcreate\t#{destination}"
|
269
|
+
end
|
270
|
+
|
271
|
+
def template_dir
|
272
|
+
File.join(File.dirname(__FILE__), 'templates')
|
273
|
+
end
|
274
|
+
|
275
|
+
def mkdir_in_target(directory)
|
276
|
+
final_destination = File.join(target_dir, directory)
|
277
|
+
|
278
|
+
FileUtils.mkdir final_destination
|
279
|
+
|
280
|
+
$stdout.puts "\tcreate\t#{directory}"
|
281
|
+
end
|
282
|
+
|
283
|
+
def touch_in_target(destination)
|
284
|
+
final_destination = File.join(target_dir, destination)
|
285
|
+
FileUtils.touch final_destination
|
286
|
+
$stdout.puts "\tcreate\t#{destination}"
|
287
|
+
end
|
288
|
+
|
289
|
+
def gitify
|
290
|
+
saved_pwd = Dir.pwd
|
291
|
+
Dir.chdir(target_dir)
|
292
|
+
begin
|
293
|
+
begin
|
294
|
+
@repo = Git.init()
|
295
|
+
rescue Git::GitExecuteError => e
|
296
|
+
raise GitInitFailed, "Encountered an error during gitification. Maybe the repo already exists, or has already been pushed to?"
|
297
|
+
end
|
298
|
+
|
299
|
+
begin
|
300
|
+
@repo.add('.')
|
301
|
+
rescue Git::GitExecuteError => e
|
302
|
+
#raise GitAddFailed, "There was some problem adding this directory to the git changeset"
|
303
|
+
raise
|
304
|
+
end
|
305
|
+
|
306
|
+
begin
|
307
|
+
@repo.commit "Initial commit to #{github_repo_name}."
|
308
|
+
rescue Git::GitExecuteError => e
|
309
|
+
raise
|
310
|
+
end
|
311
|
+
|
312
|
+
begin
|
313
|
+
@repo.add_remote('origin', github_remote)
|
314
|
+
rescue Git::GitExecuteError => e
|
315
|
+
puts "Encountered an error while adding origin remote. Maybe you have some weird settings in ~/.gitconfig?"
|
316
|
+
raise
|
317
|
+
end
|
318
|
+
ensure
|
319
|
+
Dir.chdir(saved_pwd)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def create_and_push_repo
|
324
|
+
Net::HTTP.post_form URI.parse('http://github.com/repositories'),
|
325
|
+
'login' => github_username,
|
326
|
+
'token' => github_token,
|
327
|
+
'repository[description]' => summary,
|
328
|
+
'repository[name]' => github_repo_name
|
329
|
+
# TODO do a HEAD request to see when it's ready
|
330
|
+
@repo.push('origin')
|
331
|
+
end
|
332
|
+
|
333
|
+
def enable_gem_for_repo
|
334
|
+
url = "https://github.com/#{github_username}/#{github_repo_name}/update"
|
335
|
+
`curl -F 'login=#{github_username}' -F 'token=#{github_token}' -F 'field=repository_rubygem' -F 'value=1' #{url} 2>/dev/null`
|
336
|
+
# FIXME use NET::HTTP instead of curl
|
337
|
+
#Net::HTTP.post_form URI.parse(url),
|
338
|
+
#'login' => github_username,
|
339
|
+
#'token' => github_token,
|
340
|
+
#'field' => 'repository_rubygem',
|
341
|
+
#'value' => '1'
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
end
|