Skip to content

Instantly share code, notes, and snippets.

@timbirk
Last active April 20, 2018 11:46
Show Gist options
  • Save timbirk/6225a6722bc817ead64e070f5d0e5aa4 to your computer and use it in GitHub Desktop.
Save timbirk/6225a6722bc817ead64e070f5d0e5aa4 to your computer and use it in GitHub Desktop.
Lists forks of all private repos in your org. Relies on .netrc setup.
#!/usr/bin/env ruby
require 'octokit'
if ARGV[0]
@client = Octokit::Client.new(:netrc => true, :per_page => 100,
:auto_traversal => true, :auto_paginate => true)
@client.login
private_repos = @client.org_repos(ARGV[0].to_s, {:type => 'private'}).select {
|repo| ! (repo[:forks_count] == 0 || repo[:archived])
}
private_repos.each do | repo |
begin
ghforks = @client.network(repo[:full_name])
puts repo[:full_name]
ghforks.each do | ghfork |
puts " ↳ " + ghfork[:full_name]
end
rescue Octokit::RepositoryUnavailable
next
end
end
else
STDERR.puts 'Organisation required. Example: ./private_forks.rb ITV'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment