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

Use RubyGems to fetch gems #119

Open
voxik opened this issue Aug 5, 2022 · 0 comments
Open

Use RubyGems to fetch gems #119

voxik opened this issue Aug 5, 2022 · 0 comments

Comments

@voxik
Copy link
Member

voxik commented Aug 5, 2022

Currently, the gems are fetched via URI.open from custom URL:

gem2rpm/bin/gem2rpm

Lines 52 to 67 in 331c674

if options[:fetch]
gem_uri = ''
begin
URI("https://rubygems.org/api/v1/gems/#{gemfile}.json").open do |f|
gem_uri = f.read.match(/"gem_uri":\s*"(.*?)",/m)[1]
gemfile = URI.parse(gem_uri).path.split('/').last
gemfile = File.join(out_dir, gemfile)
open(gemfile, 'w') do |gf|
gf.write(URI(gem_uri).open.read)
end
end
rescue OpenURI::HTTPError => e
Gem2Rpm.show_message("Gem fetch failed with error: #{e.message}")
exit(1)
end
end

However, it would be much better if RubyGems are used for this purpose. This would provide more consistent experience, because RubyGems are currently queried for the download URL:

gem2rpm/lib/gem2rpm.rb

Lines 46 to 62 in 331c674

def self.find_download_url(name, version)
dep = Gem::Dependency.new(name, "=#{version}")
fetcher = Gem2Rpm::SpecFetcher.new(Gem::SpecFetcher.fetcher)
spec_and_source, errors = fetcher.spec_for_dependency(dep, false)
fail DownloadUrlError, errors.first.error.message unless errors.empty?
_spec, source = spec_and_source.first
if source && source.uri
download_path = source.uri.to_s
download_path += "gems/"
end
download_path
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant