class Boilerpl8::GithubOp
Constants
- SCHEMA
Protected Instance Methods
resolve(arg, options)
click to toggle source
# File lib/boilerpl8.rb, line 173 def resolve(arg, options) arg =~ %r'\Agithub:([^/]+)/([^/]+)\z' or err("#{arg}: unexpected format.") user, repo = $1, $2 # suffix = options['B'] ? "" : "-boilerpl8" api_url = "https://api.github.com/repos/#{user}/#{repo}#{suffix}/releases" begin json_str = open(api_url) {|f| f.read } rescue OpenURI::HTTPError => ex hint = options['B'] \ ? "confirm repository name, or try without '-B' option." \ : "confirm repository name, or maybe you missed '-B' option." err("#{arg}: repository not found\n (api: GET #{api_url})\n (Hint: #{hint})") end # json_arr = JSON.parse(json_str) dict = json_arr[0] asset = (dict["assets"] || [])[0] if asset zip_url = asset["browser_download_url"] filename = zip_url ? File.basename(zip_url) : nil else zip_url = dict["zipball_url"] filename = "#{repo}_#{dict['tag_name']}.zip" end zip_url or err("ERROR: can't find zip file under github.com/#{user}/#{repo}/releases") return zip_url, filename end