lib/kpm/migrations.rb in kpm-0.8.2 vs lib/kpm/migrations.rb in kpm-0.9.0

- old
+ new

@@ -52,11 +52,11 @@ private def for_version(version = @from_version, name_only = false, migrations_to_skip = Set.new) @logger.info("Looking for migrations repository=#{@repository}, version=#{version}") - metadata = get_as_json("https://api.github.com/repos/#{@repository}/git/trees/#{version}?recursive=1&access_token=#{@oauth_token}") + metadata = get_as_json("https://api.github.com/repos/#{@repository}/git/trees/#{version}?recursive=1") migrations = [] metadata['tree'].each do |entry| match_data = KILLBILL_MIGRATION_PATH.match(entry['path']) || JAVA_PLUGIN_MIGRATION_PATH.match(entry['path']) || RUBY_PLUGIN_MIGRATION_PATH.match(entry['path']) next unless match_data @@ -65,11 +65,11 @@ @logger.debug("Found migration #{migration_name}") next if migrations_to_skip.include?(migration_name) sql = nil unless name_only - blob_metadata = get_as_json("#{entry['url']}?access_token=#{@oauth_token}") + blob_metadata = get_as_json((entry['url']).to_s) sql = decode(blob_metadata['content'], blob_metadata['encoding']) end migrations << { name: migration_name, @@ -79,11 +79,25 @@ migrations end def get_as_json(url) - raw = URI.parse(url).read - JSON.parse(raw) + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = uri.scheme == 'https' + + path = uri.path || '/' + path = "#{path}?#{uri.query}" unless uri.query.nil? + request = Net::HTTP::Get.new(path) + request['Authorization'] = "token #{@oauth_token}" unless @oauth_token.nil? + + response = http.request(request) + case response.code + when '200' + JSON.parse(response.body) + else + raise "Unable to download #{url}: #{response.code}" + end end def decode(content, encoding) if encoding == 'base64' Base64.decode64(content)