Skip to content

Instantly share code, notes, and snippets.

@andrewbigger
Last active May 3, 2017 11:47
Show Gist options
  • Save andrewbigger/d193cd7572207c4c60a29f3bfed3b84d to your computer and use it in GitHub Desktop.
Save andrewbigger/d193cd7572207c4c60a29f3bfed3b84d to your computer and use it in GitHub Desktop.
Report on Github repositories

Repo Info

Quick and dirty CSV report of a user/organisation's Github repos.

What it does

This simply creates a CSV based on the API response from Github. The values retrieved are specified in the HEADERS array, and if you feel you would like to add any items to the list, you'll find the api documentation here

Requirements

  • ruby 2.3
  • rubygems
  • optparse
  • highline/mport
  • csv

Getting Started

Installation

Before you run this script you'll need to install optparse, highline and octokit:

gem install optparse
gem install highline
gem install octokit

Then save repo_info.rb to your desktop and invoke.

Invoking the script

Simply run the script using ruby, and be sure to oprovide the organisation/username param and the output file param:

ruby ./repo_info.rb --organisation my_org --output ~/Desktop/repos.csv # to retrieve a list of organisation repos
ruby ./repo_info.rb --username myname --output ~/Desktop/repos.csv     # to retreive a list of user's repos

It will then prompt you for your github username and password:

$ Please enter your Github username
$ andrewbigger
$ Please enter your Github password
$ ************

And then it saves the CSV report to the nominated location. Easy.

Does it work with Gitlab?

Apparently Octokit works fine on Gitlab - although I have not tested this.

#!/usr/bin/env ruby
require 'rubygems'
require 'optparse'
require 'highline/import'
require 'octokit'
require 'csv'
opt = OptionParser.new do |opt|
opt.banner = "repo_info [--organisation | --username] --output"
opt.on(
'--organisation=org',
'-o=org',
"Github organisation to list"
) { |org| @user = org }
opt.on(
'--username=user',
'-u=user',
"Github username to list"
) { |user| @user = user }
opt.on(
'--output=output_location',
'-o=ouptut_location',
"Output file location"
) { |output| @output = output }
opt.on_tail('-h', '--help') do
puts opt
exit
end
end
opt.parse!(ARGV)
unless @user && @output
puts opt
exit
end
Octokit.configure do |c|
c.login = ask('Please enter your Github username')
c.password = ask('Please enter your Github password') { |i| i.echo = '*' }
c.auto_paginate = true
end
repos = Octokit.repos @user
HEADERS = [
:id,
:name,
:html_url,
:private,
:fork,
:description,
:created_at,
:updated_at
]
CSV.open(@output, 'wb') do |csv|
csv << HEADERS
repos.each do |repo_info|
csv << HEADERS.map { |h| repo_info.public_send(h) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment