Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to merge results from BigQuery Github Dataset with GitHub meta data
#Gemfile contents
source "https://rubygems.org"
gem 'octokit'
gem "pry"
# END Gemfile
require 'rubygems'
require 'bundler/setup'
require 'octokit'
require 'csv'
class GHClient
def initialize(user,token)
@client = Octokit::Client.new \
:login => user,
:password => token
@client
end
def github
@client
end
end
# get an OAuth token from your GH account management
# export your user and token to ENV and run this ruby script
@gh = GHClient.new(ENV['GH_USER'],ENV['GH_TOKEN']).github
@all_repos = File.read('./semantic-repos.txt').split("\n")
STAT_METHODS = ['stargazers_count', 'watchers_count', 'open_issues_count', 'subscribers_count', 'forks_count', 'created_at']
puts "Gathering stats"
CSV.open("/tmp/semantic_ui_repo_stats.csv","w") do |csv|
csv << STAT_METHODS.concat(['repo_name'])
@all_repos.each do |repo|
stats = STAT_METHODS.collect do |meth|
putc '.'
begin
if meth == 'created_at'
@gh.repo(repo).send(meth.to_sym).strftime('%c')
else
@gh.repo(repo).send(meth.to_sym)
end
rescue Octokit::NotFound
"NOT_FOUND"
end
end
stats = stats.concat([repo])
csv << stats
end
end
puts "CSVs generated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment