Skip to content

Commit cbce598

Browse files
authored
Merge pull request #85 from rubygems/segiddins/allow-pushing-gems-with-attestations
Allow pushing gems with attestations
2 parents 0c0c6e1 + 439206a commit cbce598

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

lib/gems/abstract_client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ def new(options = {})
1010
end
1111

1212
# Delegate to Gems::Client
13-
def method_missing(method, *args, &block)
13+
def method_missing(method, ...)
1414
return super unless new.respond_to?(method)
15-
new.send(method, *args, &block)
15+
16+
new.send(method, ...)
1617
end
1718

1819
def respond_to?(method_name, include_private = false)

lib/gems/request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def request(method, path, data, content_type, request_host = host) # rubocop:dis
3737
case content_type
3838
when 'application/x-www-form-urlencoded'
3939
request.form_data = data if %i[post put].include? method
40+
when 'multipart/form-data'
41+
request.set_form data, content_type if %i[post put].include? method
4042
when 'application/octet-stream'
4143
request.body = data
4244
request.content_length = data.size

lib/gems/v1/client.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ def gems(user_handle = nil)
6161
# @authenticated true
6262
# @param gem [File] A built gem.
6363
# @param host [String] A RubyGems compatible host to use.
64+
# @param attestations [Array] An array of attestations to push, or `nil`.
6465
# @return [String]
6566
# @example
6667
# Gems.push File.new 'pkg/gemcutter-0.2.1.gem'
67-
def push(gem, host = Configuration::DEFAULT_HOST)
68-
post('/api/v1/gems', gem.read, 'application/octet-stream', host)
68+
def push(gem, host = Configuration::DEFAULT_HOST, attestations: nil)
69+
if attestations
70+
post('/api/v1/gems',
71+
[['gem', gem.read, {:filename => gem.path, :content_type => 'application/octet-stream'}],
72+
['attestations', "[#{attestations.map(&:read).join(',')}]", {:content_type => 'application/json'}]],
73+
'multipart/form-data', host)
74+
else
75+
post('/api/v1/gems', gem.read, 'application/octet-stream', host)
76+
end
6977
end
7078

7179
# Remove a gem from RubyGems.org's index

spec/gems/client_v1_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@
110110
expect(push).to eq 'Successfully registered gem: gems (0.0.8)'
111111
end
112112
end
113+
114+
context 'with the attestations parameter' do
115+
before do
116+
stub_post('/api/v1/gems').
117+
to_return(:body => fixture('push'))
118+
end
119+
it 'submits a gem to RubyGems.org with attestations' do
120+
push = Gems.push(File.new(File.expand_path('../../fixtures/gems-0.0.8.gem', __FILE__), 'rb'), :attestations => [File.new(File.expand_path('../../fixtures/gems-0.0.8.gem', __FILE__), 'rb')])
121+
expect(a_post('/api/v1/gems')).to have_been_made
122+
expect(push).to eq 'Successfully registered gem: gems (0.0.8)'
123+
end
124+
end
113125
end
114126

115127
describe '#yank' do

0 commit comments

Comments
 (0)