-
-
Save Sixeight/c86c2f96ab00615c471f51729e8b0604 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/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