Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby bash script to download and upload gem from one Gemfury account to another

Pre-requisites:

  • Make sure we have gemfury accounts username and api access tokens
  • Install these gems gem install gemfury gem install httparty

To use this script:

./gemfury_script.rb username1 username2

#!/usr/bin/env ruby
require 'httparty'
source_username = ARGV[0]
source_api_token = ARGV[1]
source_http_download_url = "http://manage.fury.io/2/indexes/ruby/#{source_username}/download"
target_username = ARGV[2]
target_api_token = ARGV[3]
packages = %x[ fury list --as #{source_username} --api-token=#{source_api_token} ]
packages = packages.gsub("*** GEMFURY PACKAGES ***","").gsub(/\s\(\d.\d\)/,'').split("\n").reject!(&:empty?)
packages.each do |pkg|
pkg_name = pkg.gsub(/\s\((\d.\d.\d|\d.\d\|\d){,2}\)/,'')
versions = %x(fury versions #{pkg_name} --as #{source_username} --api-token=#{source_api_token})
versions = versions.split("\n").reject!(&:empty?)
if versions.length > 0
versions = versions.drop(1)
versions.each do |version|
File.open("/tmp/mygems/#{pkg_name}-#{version}.gem", "wb+") do |f|
f.write HTTParty.get(source_http_download_url + "/#{pkg_name}-#{version}/", basic_auth: {username: source_api_token })
end
end
end
end
# upload all downloaded gems to new gemfury server
%x[ echo 'Y' | fury migrate /tmp/mygems --as #{target_username} --api-token=#{target_api_token} ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment