2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2010-02-21 21:52:35 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/gemcutter_utilities'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/package'
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
class Gem::Commands::PushCommand < Gem::Command
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::GemcutterUtilities
|
|
|
|
|
|
|
|
def description # :nodoc:
|
2013-09-14 04: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-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEM built gem to push up"
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEM"
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
2013-09-14 04:59:02 -04:00
|
|
|
super 'push', 'Push a gem up to the gem server', :host => self.host
|
2013-07-08 18:41:03 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
add_proxy_option
|
2011-03-01 04:41:32 -05:00
|
|
|
add_key_option
|
|
|
|
|
2013-02-04 21:37:35 -05:00
|
|
|
add_option('--host HOST',
|
2016-09-27 21:16:43 -04:00
|
|
|
'Push to another gemcutter-compatible host') do |value, options|
|
2011-01-18 19:08:49 -05:00
|
|
|
options[:host] = value
|
|
|
|
end
|
2013-02-04 21:37:35 -05:00
|
|
|
|
|
|
|
@host = nil
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2013-02-04 21:37:35 -05:00
|
|
|
@host = options[:host]
|
|
|
|
|
|
|
|
sign_in @host
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
send_gem get_one_gem_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_gem name
|
2011-01-18 19:08:49 -05:00
|
|
|
args = [:post, "api/v1/gems"]
|
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
latest_rubygems_version = Gem.latest_rubygems_version
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
if latest_rubygems_version < Gem.rubygems_version and
|
|
|
|
Gem.rubygems_version.prerelease? and
|
2013-02-04 21:37:35 -05:00
|
|
|
Gem::Version.new('2.0.0.rc.2') != Gem.rubygems_version then
|
2012-12-22 19:35:09 -05: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-04 21:37:35 -05:00
|
|
|
|
|
|
|
You can upgrade or downgrade to the latest release version with:
|
|
|
|
|
|
|
|
gem update --system=#{latest_rubygems_version}
|
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
ERROR
|
2011-03-01 04:41:32 -05:00
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
2013-09-18 17:29:41 -04:00
|
|
|
gem_data = Gem::Package.new(name)
|
|
|
|
|
2013-02-04 21:37:35 -05:00
|
|
|
unless @host then
|
2013-09-18 17:29:41 -04:00
|
|
|
@host = gem_data.spec.metadata['default_gem_server']
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
push_host = nil
|
2013-09-18 17:29:41 -04:00
|
|
|
|
|
|
|
if gem_data.spec.metadata.has_key?('allowed_push_host')
|
2016-03-03 19:29:40 -05:00
|
|
|
push_host = gem_data.spec.metadata['allowed_push_host']
|
2013-09-18 17:29:41 -04:00
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
@host ||= push_host
|
|
|
|
|
|
|
|
# Always include @host, even if it's nil
|
|
|
|
args += [ @host, push_host ]
|
|
|
|
|
2013-02-04 21:37:35 -05:00
|
|
|
say "Pushing gem to #{@host || Gem.host}..."
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
response = rubygems_api_request(*args) do |request|
|
2010-02-21 21:52:35 -05: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 04:41:32 -05:00
|
|
|
request.add_field "Authorization", api_key
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_response response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|