Skip to content

Instantly share code, notes, and snippets.

@ethanp
Created August 13, 2015 22:46
Show Gist options
  • Save ethanp/358b6d572b3ff5b6b70c to your computer and use it in GitHub Desktop.
Save ethanp/358b6d572b3ff5b6b70c to your computer and use it in GitHub Desktop.
Find the last page of commits to master for a given github repository
#!/usr/bin/env ruby
user, repo = ARGV
if `which curl`.length == 0
puts "please install curl"
exit 1
end
repo_loc = "https://github.com/#{user}/#{repo}"
base_url = "#{repo_loc}/commits/master?page="
def is_404(url)
`curl -s --head #{url} | head -n1` =~ /404 Not Found/
end
if is_404(repo_loc)
puts "#{user} #{repo} could not be found on GitHub"
exit 2
end
lo = 1
hi = 500
while lo <= hi do
page_num = (lo+hi)/2
if is_404 "#{base_url}#{page_num}"
puts "didn't find #{page_num}"
hi = page_num - 1
minus = 1
else
puts "found #{page_num}"
lo = page_num + 1
minus = 0
end
end
puts "#{base_url}#{page_num-minus}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment