Created
September 27, 2017 18:43
-
-
Save matsadler/01a60e5829127a962eeaebb8524714d7 to your computer and use it in GitHub Desktop.
Prints forks of private repos
This file contains hidden or 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
require "net/https" | |
require "json" | |
GITHUB_OAUTH_TOKEN = <YOUR OAUTH TOKEN HERE> | |
GITHUB_ORG_NAME = <YOUR ORG> | |
def api_request(http, path) | |
request = Net::HTTP::Get.new(path) | |
request["Authorization"] = "token #{GITHUB_OAUTH_TOKEN}" | |
response = http.request(request) | |
%r{<(?<next_page>.*)>; rel="next"} =~ response["Link"].to_s | |
data = response.content_type =~ /json/ ? JSON.parse(response.body) : response.body | |
[data, next_page] | |
end | |
http = Net::HTTP.start("api.github.com", 443, use_ssl: true) | |
next_page = "/orgs/#{GITHUB_ORG_NAME}/repos?type=private" | |
while next_page | |
data, next_page = api_request(http, next_page) | |
data.each do |repo| | |
forks, _ = api_request(http, repo["forks_url"]) | |
forks.each do |fork| | |
puts fork["full_name"] if fork["fork"] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment