diff options
Diffstat (limited to 'src/update_assets.rb')
-rwxr-xr-x | src/update_assets.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/update_assets.rb b/src/update_assets.rb index b4aaba54..531a8eeb 100755 --- a/src/update_assets.rb +++ b/src/update_assets.rb @@ -1,19 +1,20 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # http://www.rubydoc.info/github/rest-client/rest-client/RestClient require 'rest_client' require 'json' if ARGV.length < 3 - puts "usage: #$0 <token> <version> <files...>" + puts "usage: #{$PROGRAM_NAME} <token> <version> <files...>" exit 1 end token, version, *files = ARGV -base = "https://api.github.com/repos/junegunn/fzf-bin/releases" +base = 'https://api.github.com/repos/junegunn/fzf-bin/releases' # List releases -rels = JSON.parse(RestClient.get(base, :authorization => "token #{token}")) +rels = JSON.parse(RestClient.get(base, authorization: "token #{token}")) rel = rels.find { |r| r['tag_name'] == version } unless rel puts "#{version} not found" @@ -21,25 +22,26 @@ unless rel end # List assets -assets = Hash[rel['assets'].map { |a| a.values_at *%w[name id] }] +assets = Hash[rel['assets'].map { |a| a.values_at('name', 'id') }] -files.select { |f| File.exists? f }.map do |file| +files.select { |f| File.exist?(f) }.map do |file| Thread.new do - name = File.basename file + name = File.basename(file) - if asset_id = assets[name] + if asset_id = assets[name] # rubocop:todo Lint/AssignmentInCondition puts "#{name} found. Deleting asset id #{asset_id}." - RestClient.delete "#{base}/assets/#{asset_id}", - :authorization => "token #{token}" + RestClient.delete("#{base}/assets/#{asset_id}", + authorization: "token #{token}") else puts "#{name} not found" end puts "Uploading #{name}" RestClient.post( - "#{base.sub 'api', 'uploads'}/#{rel['id']}/assets?name=#{name}", + "#{base.sub('api', 'uploads')}/#{rel['id']}/assets?name=#{name}", File.read(file), - :authorization => "token #{token}", - :content_type => "application/octet-stream") + authorization: "token #{token}", + content_type: 'application/octet-stream' + ) end end.each(&:join) |