Permalink
Browse files

Fixed #230 - Instead of relying on Github API which is not supported …

…anymore, use Github API to login using basic auth and create a repo using the API.
  • Loading branch information...
1 parent b8e36db commit 0c1a68433e9f8bbc09cabc5e03ef2dac5b93c1b1 @emilsoman emilsoman committed Nov 28, 2012
View
@@ -4,6 +4,8 @@ source "http://gems.github.com"
gem "rake"
gem "git", ">= 1.2.5"
+gem "github_api", ">= 0.8.1"
+gem "highline", ">= 1.6.15"
gem "bundler", "~> 1.0"
gem "rdoc"
View
@@ -1,9 +1,11 @@
PATH
remote: .
specs:
- jeweler (1.8.3)
+ jeweler (1.8.4)
bundler (~> 1.0)
git (>= 1.2.5)
+ github_api (>= 0.8.1)
+ highline (>= 1.6.15)
rake
rdoc
@@ -12,6 +14,7 @@ GEM
remote: http://gems.github.com/
specs:
activesupport (2.3.8)
+ archive-tar-minitar (0.5.2)
bluecloth (2.0.7)
builder (3.0.0)
columnize (0.3.6)
@@ -22,27 +25,54 @@ GEM
json (>= 1.4.6)
term-ansicolor (>= 1.0.6)
diff-lcs (1.1.3)
+ faraday (0.8.4)
+ multipart-post (~> 1.1)
gherkin (2.7.4)
json (>= 1.4.6)
git (1.2.5)
+ github_api (0.8.1)
+ faraday (~> 0.8.1)
+ hashie (~> 1.2.0)
+ multi_json (~> 1.3)
+ nokogiri (~> 1.5.2)
+ oauth2
+ hashie (1.2.0)
+ highline (1.6.15)
+ httpauth (0.2.0)
json (1.6.3)
- linecache (0.46)
- rbx-require-relative (> 0.0.4)
+ jwt (0.1.5)
+ multi_json (>= 1.0)
+ linecache19 (0.5.13)
+ ruby_core_source (>= 0.1.4)
mhennemeyer-output_catcher (1.0.1)
mocha (0.9.8)
rake
+ multi_json (1.3.7)
+ multipart-post (1.1.5)
+ nokogiri (1.5.5)
+ oauth2 (0.8.0)
+ faraday (~> 0.8)
+ httpauth (~> 0.1)
+ jwt (~> 0.1.4)
+ multi_json (~> 1.0)
+ rack (~> 1.2)
+ rack (1.4.1)
rake (0.9.2.2)
- rbx-require-relative (0.0.5)
rcov (0.9.8)
rdoc (3.12)
json (~> 1.4)
redgreen (1.2.2)
rr (1.0.4)
- ruby-debug (0.10.4)
- columnize (>= 0.1)
- ruby-debug-base (~> 0.10.4.0)
- ruby-debug-base (0.10.4)
- linecache (>= 0.3)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
shoulda (2.11.3)
term-ansicolor (1.0.7)
test-construct (1.2.0)
@@ -58,6 +88,8 @@ DEPENDENCIES
bundler (~> 1.0)
cucumber (~> 1.1.4)
git (>= 1.2.5)
+ github_api (>= 0.8.1)
+ highline (>= 1.6.15)
jeweler!
mhennemeyer-output_catcher
mocha
@@ -66,7 +98,7 @@ DEPENDENCIES
rdoc
redgreen
rr (~> 1.0.4)
- ruby-debug
+ ruby-debug19
shoulda
test-construct
timecop
View
0 bin/jeweler 100644 → 100755
No changes.
@@ -56,15 +56,13 @@
@user_email = 'bar@example.com'
@user_name = 'foo'
@github_user = 'technicalpickles'
- @github_token = 'zomgtoken'
require 'git'
Git.stubs(:global_config).
returns({
'user.name' => @user_name,
'user.email' => @user_email,
- 'github.user' => @github_user,
- 'github.token' => @github_token})
+ 'github.user' => @github_user})
end
Given /^I set JEWELER_OPTS env variable to "(.*)"$/ do |val|
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Josh Nichols"]
- s.date = "2012-06-22"
+ s.date = "2012-11-28"
s.description = "Simple and opinionated helper for creating Rubygem projects on GitHub"
s.email = "josh@technicalpickles.com"
s.executables = ["jeweler"]
@@ -183,7 +183,7 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/technicalpickles/jeweler"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
- s.rubygems_version = "1.8.15"
+ s.rubygems_version = "1.8.24"
s.summary = "Opinionated tool for creating and managing RubyGem projects"
if s.respond_to? :specification_version then
@@ -192,6 +192,8 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [">= 0"])
s.add_runtime_dependency(%q<git>, [">= 1.2.5"])
+ s.add_runtime_dependency(%q<github_api>, [">= 0.8.1"])
+ s.add_runtime_dependency(%q<highline>, [">= 1.6.15"])
s.add_runtime_dependency(%q<bundler>, ["~> 1.0"])
s.add_runtime_dependency(%q<rdoc>, [">= 0"])
s.add_development_dependency(%q<yard>, ["~> 0.7.4"])
@@ -202,6 +204,8 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<git>, [">= 1.2.5"])
+ s.add_dependency(%q<github_api>, [">= 0.8.1"])
+ s.add_dependency(%q<highline>, [">= 1.6.15"])
s.add_dependency(%q<bundler>, ["~> 1.0"])
s.add_dependency(%q<rdoc>, [">= 0"])
s.add_dependency(%q<yard>, ["~> 0.7.4"])
@@ -213,6 +217,8 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<git>, [">= 1.2.5"])
+ s.add_dependency(%q<github_api>, [">= 0.8.1"])
+ s.add_dependency(%q<highline>, [">= 1.6.15"])
s.add_dependency(%q<bundler>, ["~> 1.0"])
s.add_dependency(%q<rdoc>, [">= 0"])
s.add_dependency(%q<yard>, ["~> 0.7.4"])
@@ -1,4 +1,6 @@
require 'git'
+require 'github_api'
+require 'highline/import'
require 'erb'
require 'net/http'
@@ -20,10 +22,10 @@ class NoGitHubRepoNameGiven < StandardError
end
class NoGitHubUser < StandardError
end
- class NoGitHubToken < StandardError
- end
class GitInitFailed < StandardError
end
+ class GitRepoCreationFailed < StandardError
+ end
# Generator for creating a jeweler-enabled project
class Generator
@@ -46,7 +48,7 @@ class Generator
require 'jeweler/generator/yard_mixin'
attr_accessor :target_dir, :user_name, :user_email, :summary, :homepage,
- :description, :project_name, :github_username, :github_token,
+ :description, :project_name, :github_username,
:repo, :should_create_remote_repo,
:testing_framework, :documentation_framework,
:should_use_cucumber, :should_use_bundler,
@@ -128,7 +130,7 @@ def run
$stdout.puts "Jeweler has prepared your gem in #{target_dir}"
if should_create_remote_repo
create_and_push_repo
- $stdout.puts "Jeweler has pushed your repo to #{homepage}"
+ $stdout.puts "Jeweler has pushed your repo to #{git_remote}"
end
end
@@ -283,11 +285,18 @@ def create_version_control
end
def create_and_push_repo
- Net::HTTP.post_form URI.parse('http://github.com/api/v2/yaml/repos/create'),
- 'login' => github_username,
- 'token' => github_token,
- 'description' => summary,
- 'name' => project_name
+ puts "Please provide your Github password to create the Github repository"
+ begin
+ login = github_username
+ password = ask("Password: ") { |q| q.echo = false }
+ github = Github.new(login: login.strip, password: password.strip)
+ github.repos.create(name: project_name, description: summary)
+ rescue Github::Error::Unauthorized
+ puts "Wrong login/password! Please try again"
+ retry
+ rescue Github::Error::UnprocessableEntity
+ raise GitRepoCreationFailed, "Can't create that repo. Does it already exist?"
+ end
# TODO do a HEAD request to see when it's ready?
@repo.push('origin')
end
@@ -40,10 +40,7 @@ def run!(*arguments)
$stderr.puts %Q{No user.email found in ~/.gitconfig. Please tell git about yourself (see http://help.github.com/git-email-settings/ for details). For example: git config --global user.email mad.vooo@gmail.com}
return 1
rescue Jeweler::NoGitHubUser
- $stderr.puts %Q{No github.user found in ~/.gitconfig. Please tell git about your GitHub account (see http://github.com/blog/180-local-github-config for details). For example: git config --global github.user defunkt}
- return 1
- rescue Jeweler::NoGitHubToken
- $stderr.puts %Q{No github.token found in ~/.gitconfig. Please tell git about your GitHub account (see http://github.com/blog/180-local-github-config for details). For example: git config --global github.token 6ef8395fecf207165f1a82178ae1b984}
+ $stderr.puts %Q{Please specify --github-username or set github.user in ~/.gitconfig (see http://github.com/blog/180-local-github-config for details). For example: git config --global github.user defunkt}
return 1
rescue Jeweler::FileInTheWay
$stderr.puts "The directory #{options[:project_name]} already exists. Maybe move it out of the way before continuing?"
@@ -3,18 +3,11 @@ class Generator
module GithubMixin
def self.extended(generator)
generator.github_username = generator.options[:github_username]
- generator.github_token = generator.options[:github_token]
generator.should_create_remote_repo = generator.options[:create_repo]
unless generator.github_username
raise NoGitHubUser
end
-
- if generator.should_create_remote_repo
- unless generator.github_token
- raise NoGitHubToken
- end
- end
end
def git_remote
@@ -14,7 +14,6 @@ def initialize(args)
self[:user_name] = ENV['GIT_AUTHOR_NAME'] || ENV['GIT_COMMITTER_NAME'] || git_config['user.name']
self[:user_email] = ENV['GIT_AUTHOR_EMAIL'] || ENV['GIT_COMMITTER_EMAIL'] || git_config['user.email']
self[:github_username] = git_config['github.user']
- self[:github_token] = git_config['github.token']
require 'optparse'
@opts = OptionParser.new do |o|
@@ -109,10 +108,6 @@ def initialize(args)
self[:github_username] = github_username
end
- o.on('--github-token [GITHUB_TOKEN]', "GitHub token to use for interacting with the GitHub API") do |github_token|
- self[:github_token] = github_token
- end
-
o.on('--git-remote [GIT_REMOTE]', 'URI to set the git origin remote to') do |git_remote|
self[:git_remote] = git_remote
end
@@ -47,11 +47,6 @@ def self.for_options(*options)
should "use github username from git config" do
assert_equal @github_user, @options[:github_username]
end
-
- should "use github token from git config" do
- assert_equal @github_token, @options[:github_token]
- end
-
should "use user name from git config" do
assert_equal @git_name, @options[:user_name]
end
@@ -203,12 +198,6 @@ def self.for_options(*options)
end
end
- for_options '--github-token', 'mygithubtoken' do
- should "set github token" do
- assert_equal 'mygithubtoken', @options[:github_token]
- end
- end
-
for_options '--bundler' do
should "use bundler" do
assert @options[:use_bundler]
@@ -7,7 +7,6 @@ def build_generator(testing_framework = :shoulda, options = {})
:user_name => 'John Doe',
:user_email => 'john@example.com',
:github_username => 'johndoe',
- :github_token => 'yyz',
:documentation_framework => :rdoc
}.merge(options)
@@ -52,25 +52,11 @@ def setup
end
end
end
-
- context "without github token set" do
- setup do
- stub_git_config
- end
-
- should 'raise NoGitHubToken if creating repo' do
- assert_raise Jeweler::NoGitHubToken do
- Jeweler::Generator.new(:project_name => @project_name, :user_name => @git_name, :user_email => @git_email, :github_username => @github_user, :create_repo => true, :testing_framework => :shoulda, :documentation_framework => :rdoc)
- end
- end
- end
-
def build_generator(options = {})
defaults = { :project_name => @project_name,
:user_name => @git_name,
:user_email => @git_email,
:github_username => @github_user,
- :github_token => @github_token,
:testing_framework => :shoulda,
:documentation_framework => :rdoc }
View
@@ -163,10 +163,9 @@ def set_default_git_config
@git_name = 'foo'
@git_email = 'bar@example.com'
@github_user = 'technicalpickles'
- @github_token = 'zomgtoken'
end
def valid_git_config
- { 'user.name' => @git_name, 'user.email' => @git_email, 'github.user' => @github_user, 'github.token' => @github_token }
+ { 'user.name' => @git_name, 'user.email' => @git_email, 'github.user' => @github_user }
end
end

0 comments on commit 0c1a684

Please sign in to comment.