Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧑‍🔬 Prototype: Push multiple gems at once #2

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/rubygems/commands/push_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ def initialize
end

def execute
gem_name = get_one_gem_name
default_gem_server, push_host = get_hosts_for(gem_name)
gem_names = get_all_gem_names

hosts_from_gems = gem_names.map do |gem_name|
get_hosts_for(gem_name)
end
too_many_hosts = hosts_from_gems.uniq.count > 1

raise "All gems must have the same host" if too_many_hosts

default_gem_server, push_host = hosts_from_gems.first

@host = if @user_defined_host
options[:host]
Expand All @@ -63,7 +71,9 @@ def execute

sign_in @host, scope: get_push_scope

send_gem(gem_name)
gem_names.each do |gem_name|
send_gem(gem_name)
Copy link
Author

@aellispierce aellispierce Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToDo: Rescue any failures

end
end

def send_gem(name)
Expand Down
45 changes: 45 additions & 0 deletions test/rubygems/test_gem_commands_push_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,51 @@ def test_sending_gem
send_battery
end

def test_sending_multiple_gems_to_same_host
@first_response = "Successfully registered gem: freebird (1.0.0)"
@second_response = "Successfully registered gem: cagedbird (1.0.0)"
@fetcher.data["#{@host}/api/v1/gems"] = [[@first_response, 200, 'OK'], [@second_response, 200, 'OK']]

spec_1, path_1 = util_gem "freebird", "1.0.1" do |spec|
spec.metadata['allowed_push_host'] = @host
end

spec_2, path_2 = util_gem "cagedbird", "1.0.1" do |spec|
spec.metadata['allowed_push_host'] = @host
end
@cmd.options[:args] = [path_1, path_2]
use_ui @ui do
@cmd.instance_variable_set :@host, @host
@cmd.execute
end

assert_match %r{Successfully registered gem: freebird}, @ui.output
assert_match %r{Successfully registered gem: cagedbird}, @ui.output
end

def test_sending_multiple_gems_to_different_hosts
@host = "http://privategemserver.example"

@first_response = "Successfully registered gem: freebird (1.0.0)"
@second_response = "Successfully registered gem: cagedbird (1.0.0)"
@fetcher.data["#{@host}/api/v1/gems"] = [[@first_response, 200, 'OK'], [@second_response, 200, 'OK']]

spec_1, path_1 = util_gem "freebird", "1.0.1" do |spec|
spec.metadata['allowed_push_host'] = @host
end

spec_2, path_2 = util_gem "cagedbird", "1.0.1" do |spec|
spec.metadata['allowed_push_host'] = "https://rubygems.example"
end
@cmd.options[:args] = [path_1, path_2]
assert_raises "All gems must have the same host" do
use_ui @ui do
@cmd.instance_variable_set :@host, @host
@cmd.execute
end
end
end

def test_sending_gem_to_allowed_push_host
@host = "http://privategemserver.example"

Expand Down