Skip to content

Instantly share code, notes, and snippets.

@ryu39
Created August 2, 2017 04:02
Show Gist options
  • Save ryu39/4849a0d94b8a224d9e6d072b3d9c556d to your computer and use it in GitHub Desktop.
Save ryu39/4849a0d94b8a224d9e6d072b3d9c556d to your computer and use it in GitHub Desktop.
require 'csv'
require 'uri'
require 'net/http'
require 'json'
CSV_REPOS_DATA = <<EOS
discourse,discourse,https://github.com/discourse/discourse
gitlabhq,gitlabhq,https://github.com/gitlabhq/gitlabhq
huginn,huginn,https://github.com/huginn/huginn
diaspora,diaspora,https://github.com/diaspora/diaspora
tootsuite,mastodon,https://github.com/tootsuite/mastodon
errbit,errbit,https://github.com/errbit/errbit
fatfreecrm,fat_free_crm,https://github.com/fatfreecrm/fat_free_crm
edavis10,redmine,https://github.com/edavis10/redmine
Netflix,Scumblr,https://github.com/Netflix/Scumblr
locomotivecms,engine,https://github.com/locomotivecms/engine
rubygems,rubygems.org,https://github.com/rubygems/rubygems.org
opf,openproject,https://github.com/opf/openproject
houndci,hound,https://github.com/houndci/hound
loomio,loomio,https://github.com/loomio/loomio
jcs,lobsters,https://github.com/jcs/lobsters
EOS
repositories = CSV.parse(CSV_REPOS_DATA)
class ApiClient
def initialize(access_token)
@access_token = access_token
end
def get(url)
url = URI.parse(url)
req = Net::HTTP::Get.new(url)
req.add_field("Authorization", "token #{@access_token}")
Net::HTTP.new(url.host, url.port).tap { |http| http.use_ssl = true}.start do |http|
http.request(req)
end
end
end
api_client = ApiClient.new(ENV['GITHUB_API_ACCESS_TOKEN'])
result = repositories.map do |owner, repo, _|
response = api_client.get("https://api.github.com/repos/#{owner}/#{repo}/contents/app")
directories = JSON.parse(response.body).select { |item| item['type'] == 'dir' }
directory_names = directories.map { |d| d['name'] }
["#{owner}/#{repo}", directory_names]
end
summary = Hash.new { |h, k| h[k] = [] }
result.each do |repo, dirs|
dirs.each do |dir|
summary[dir] << repo
end
end
summary.each do |key, dirs|
puts "#{key} #{dirs.length} #{dirs.join(',')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment