Skip to content

Instantly share code, notes, and snippets.

@muizidn
Last active August 10, 2019 13:41
Show Gist options
  • Save muizidn/75ce4ee98458009eab7b6bd03e95d345 to your computer and use it in GitHub Desktop.
Save muizidn/75ce4ee98458009eab7b6bd03e95d345 to your computer and use it in GitHub Desktop.
Check git size
require 'open-uri'
require 'json'
url = ARGV[0]
uri = URI.parse(url)
api_uri = "https://api.github.com/repos" + uri.path
puts "fetch from: #{api_uri}"
json_string = URI.parse(api_uri).read
json = JSON.parse(json_string)
size = json["size"]
reposize = case size
when 0..1024 then "#{size} kb"
when 1024..1024**2 then "#{size / 1024}+ mb"
when 1024**2..1024**3 then "#{size / 1024**2}+ gb"
when 1024**3..1024**4 then "#{size / 1024**3}+ tb"
when 1024**4..1024**5 then "#{size / 1024**4}+ pb"
else "Unknown"
end
puts "Size #{size} = #{reposize}"%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment