Skip to content

Instantly share code, notes, and snippets.

@seanrankin
Created November 3, 2014 21:18
Show Gist options
  • Save seanrankin/8a1af611c9b613ecbe15 to your computer and use it in GitHub Desktop.
Save seanrankin/8a1af611c9b613ecbe15 to your computer and use it in GitHub Desktop.
A simple Ruby script that queries the github api for most active repos, and takes some arguments.
#!/usr/bin/env ruby
# A simple Ruby script that queries the github api for most active repos, and takes some arguments.
# Example => $ ./active_github_repos.rb --after 2004-01-01 --before 2014-01-31 --event tits --count 5
require "optparse"
options = {:after => nil, :before => nil, :event => nil, :count => nil}
parser = OptionParser.new do|opts|
opts.banner = "Usage: gh_repo_stats [--after DATETIME] [--before DATETIME] [--event EVENT_NAME] [-n COUNT]"
opts.on('-a', '--after after', 'After') do |after|
options[:after] = after;
end
opts.on('-b', '--before before', 'Before') do |before|
options[:before] = before;
end
opts.on('-e', '--event event', 'Event') do |event|
options[:event] = event;
end
opts.on('-c', '--count count', 'Count') do |count|
options[:count] = count;
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
parser.parse!
if options[:after] == nil
print 'Enter start date in YYYY-MM-DD format: '
options[:after] = gets.chomp
end
if options[:before] == nil
print 'Enter end date in YYYY-MM-DD format: '
options[:before] = gets.chomp
end
if options[:event] == nil
print 'Enter an event (like push or c): '
options[:before] = gets.chomp
end
if options[:count] == nil
print 'How many records do you want to return? '
options[:before] = gets.chomp
end
puts `curl -G -s https://api.github.com/search/repositories \
--data-urlencode 'q=created:#{options[:after]}..#{options[:before]}' \
--data-urlencode 'per_page=#{options[:count]}' \
--data-urlencode 'sort=stars' \
--data-urlencode 'order=desc' \
| jq '.items[] | .full_name' -r`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment