Created
July 7, 2020 21:03
-
-
Save cjavilla-stripe/0365a4eb056fc3a732d016e480be9c70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'octokit' | |
require 'dotenv' | |
require 'restclient' | |
require 'json' | |
Dotenv.load('.env_shortcut') | |
GITHUB = "https://raw.githubusercontent.com/%s/master/.cli.json" | |
# Set access_token instead of login and password if you use personal access token | |
client = Octokit::Client.new(access_token: ENV['GK']) | |
results = [] | |
results << [ | |
'name', | |
'full name', | |
'forks_count', | |
'open_issues_count', | |
'stargazers_count', | |
'watchers_count', | |
'unique_clones', | |
'unique_views', | |
'top_paths', | |
'top_sources' | |
].join(",") | |
# Fetch the current user | |
repo = client.org_repos('stripe-samples', per_page: 100).each do |repo| | |
# begin | |
# response = RestClient.get(GITHUB % repo.full_name) | |
# p JSON.parse(response) | |
# has_cli = true | |
# rescue RestClient::NotFound => e | |
# has_cli = false | |
# rescue => e | |
# p e | |
# end | |
unique_clones = client.clones(repo.full_name)[:uniques] | |
unique_views = client.views(repo.full_name)[:uniques] | |
top_paths = client.top_paths(repo.full_name).map{|tp| "#{tp[:path]}:#{tp[:uniques]}" }.join("|") | |
top_sources = client.top_referrers(repo.full_name).map{|tp| "#{tp[:referrer]}:#{tp[:uniques]}" }.join("|") | |
puts "----------\n\n" | |
results << [ | |
repo.name, | |
repo.full_name, | |
repo.forks_count, | |
repo.open_issues_count, | |
repo.stargazers_count, | |
repo.watchers_count, | |
unique_clones, | |
unique_views, | |
top_paths, | |
top_sources | |
].join(",") | |
end | |
puts results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment