Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Last active March 5, 2022 15:28
Show Gist options
  • Save Sixeight/c86c2f96ab00615c471f51729e8b0604 to your computer and use it in GitHub Desktop.
Save Sixeight/c86c2f96ab00615c471f51729e8b0604 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# frozen_string_literal: true
abort 'ruby collect_repositories.rb [org|user] <NAME>' unless ARGV.length >= 1
org_or_user = %w[org user].include?(ARGV[0]) ? ARGV[0] : 'org'
name = ARGV[1] || ARGV[0]
per_page = (ARGV[2] || 100).to_i
# https://docs.github.com/ja/rest/reference/repos#list-organization-repositories
# https://docs.github.com/ja/rest/reference/repos#list-repositories-for-a-user
loop.with_index do |_, page|
puts repositories = `gh api -XGET -Fper_page=#{per_page} -Fpage=#{page} '/#{org_or_user}s/#{name}/repos' --jq '.[] | .ssh_url'`.split("\n")
break if repositories.length <= 0 || repositories.length % per_page != 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment