added:src/update_assets.rb+41 added
1+#!/usr/bin/env ruby2+3+# http://www.rubydoc.info/github/rest-client/rest-client/RestClient4+require 'rest_client'5+6+if ARGV.length < 37+ puts "usage: #$0 <token> <version> <files...>"8+end9+10+token, version, *files = ARGV11+base = "https://api.github.com/repos/junegunn/fzf-bin/releases"12+13+# List releases14+rels = JSON.parse(RestClient.get(base, :authorization => "token #{token}"))15+rel = rels.find { |r| r['tag_name'] == version }16+unless rel17+ puts "#{version} not found"18+ exit 119+end20+21+# List assets22+assets = Hash[rel['assets'].map { |a| a.values_at *%w[name id] }]23+24+files.select { |f| File.exists? f }.each do |file|25+ name = File.basename file26+27+ if asset_id = assets[name]28+ puts "#{name} found. Deleting asset id #{asset_id}."29+ RestClient.delete "#{base}/assets/#{asset_id}",30+ :authorization => "token #{token}"31+ else32+ puts "#{name} not found"33+ end34+35+ puts "Uploading #{name}"36+ RestClient.post(37+ "#{base.sub 'api', 'uploads'}/#{rel['id']}/assets?name=#{name}",38+ File.read(file),39+ :authorization => "token #{token}",40+ :content_type => "application/octet-stream")41+end