1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Octokitを使って組織配下のリポジトリリストを取得する

Posted at

Octokitのruby版を使ってあるOrganization配下のリポジトリリストを作ってみました。CSVで書き出してます。

コードはprivateとpublicだけ絞って出してます(forkは除きたかった)。access_tokenはここで発行可能です。

# *****はGithubで発行したアクセストークン
client = Octokit::Client.new(:access_token => "*****")

privates = client.organization_repositories('組織名', {:type => 'private'})
publics = client.organization_repositories('組織名', {:type => 'public'})
repos = privates.concat(publics)

csv_text = CSV.generate do |csv|
  repos.each do |repo|
    csv << [
      repo[:name],
      repo[:private] ? :private : :public,
      repo[:html_url],
      Time.zone.parse(repo[:pushed_at].to_s).strftime('%Y-%m-%d %H:%M:%S'),
      Time.zone.parse(repo[:created_at].to_s).strftime('%Y-%m-%d %H:%M:%S')
    ]
  end
end

File.write(Rails.root.join('tmp', 'repos.csv'), csv_text)

bin/rails consoleで実行してるので少し依存したコードがありますけど当然rails関係ないです。素でやるとrequire 'csv'とかrequire 'octokit'必要かと思います。またpushed_atみたいな時間計はUTCで来ますのでJSTへの変換が必要です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?