2010-02-22 05:52:35 +03:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/gemcutter_utilities'
|
2012-11-29 10:52:18 +04:00
|
|
|
require 'rubygems/package'
|
2010-02-22 05:52:35 +03:00
|
|
|
|
|
|
|
class Gem::Commands::PushCommand < Gem::Command
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::GemcutterUtilities
|
|
|
|
|
|
|
|
def description # :nodoc:
|
2013-09-14 12:59:02 +04:00
|
|
|
<<-EOF
|
|
|
|
The push command uploads a gem to the push server (the default is
|
|
|
|
https://rubygems.org) and adds it to the index.
|
|
|
|
|
|
|
|
The gem can be removed from the index (but only the index) using the yank
|
|
|
|
command. For further discussion see the help for the yank command.
|
|
|
|
EOF
|
2010-02-22 05:52:35 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEM built gem to push up"
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEM"
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
2013-09-14 12:59:02 +04:00
|
|
|
super 'push', 'Push a gem up to the gem server', :host => self.host
|
2013-07-09 02:41:03 +04:00
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
add_proxy_option
|
2011-03-01 12:41:32 +03:00
|
|
|
add_key_option
|
|
|
|
|
2013-02-05 06:37:35 +04:00
|
|
|
add_option('--host HOST',
|
|
|
|
'Push to another gemcutter-compatible host') do |value, options|
|
2011-01-19 03:08:49 +03:00
|
|
|
options[:host] = value
|
|
|
|
end
|
2013-02-05 06:37:35 +04:00
|
|
|
|
|
|
|
@host = nil
|
2010-02-22 05:52:35 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2013-02-05 06:37:35 +04:00
|
|
|
@host = options[:host]
|
|
|
|
|
|
|
|
sign_in @host
|
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
send_gem get_one_gem_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_gem name
|
2011-01-19 03:08:49 +03:00
|
|
|
args = [:post, "api/v1/gems"]
|
|
|
|
|
2012-12-23 04:35:09 +04:00
|
|
|
latest_rubygems_version = Gem.latest_rubygems_version
|
2010-02-22 05:52:35 +03:00
|
|
|
|
2012-12-23 04:35:09 +04:00
|
|
|
if latest_rubygems_version < Gem.rubygems_version and
|
|
|
|
Gem.rubygems_version.prerelease? and
|
2013-02-05 06:37:35 +04:00
|
|
|
Gem::Version.new('2.0.0.rc.2') != Gem.rubygems_version then
|
2012-12-23 04:35:09 +04:00
|
|
|
alert_error <<-ERROR
|
|
|
|
You are using a beta release of RubyGems (#{Gem::VERSION}) which is not
|
|
|
|
allowed to push gems. Please downgrade or upgrade to a release version.
|
|
|
|
|
|
|
|
The latest released RubyGems version is #{latest_rubygems_version}
|
2013-02-05 06:37:35 +04:00
|
|
|
|
|
|
|
You can upgrade or downgrade to the latest release version with:
|
|
|
|
|
|
|
|
gem update --system=#{latest_rubygems_version}
|
|
|
|
|
2012-12-23 04:35:09 +04:00
|
|
|
ERROR
|
2011-03-01 12:41:32 +03:00
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
2013-09-19 01:29:41 +04:00
|
|
|
gem_data = Gem::Package.new(name)
|
|
|
|
|
2013-02-05 06:37:35 +04:00
|
|
|
unless @host then
|
2013-09-19 01:29:41 +04:00
|
|
|
@host = gem_data.spec.metadata['default_gem_server']
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
|
|
|
|
2013-09-19 01:29:41 +04:00
|
|
|
# Always include this, even if it's nil
|
|
|
|
args << @host
|
|
|
|
|
|
|
|
if gem_data.spec.metadata.has_key?('allowed_push_host')
|
|
|
|
args << gem_data.spec.metadata['allowed_push_host']
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-05 06:37:35 +04:00
|
|
|
say "Pushing gem to #{@host || Gem.host}..."
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2011-01-19 03:08:49 +03:00
|
|
|
response = rubygems_api_request(*args) do |request|
|
2010-02-22 05:52:35 +03:00
|
|
|
request.body = Gem.read_binary name
|
|
|
|
request.add_field "Content-Length", request.body.size
|
|
|
|
request.add_field "Content-Type", "application/octet-stream"
|
2011-03-01 12:41:32 +03:00
|
|
|
request.add_field "Authorization", api_key
|
2010-02-22 05:52:35 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
with_response response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|