Skip to content

Instantly share code, notes, and snippets.

@timurvafin
Created January 13, 2012 12:38

Revisions

  1. timurvafin created this gist Jan 13, 2012.
    5 changes: 5 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    source 'http://rubygems.org'

    gem 'i18n'
    gem 'activesupport', '>= 2.3.5'
    gem 'octokit', '~> 0.6.0'
    30 changes: 30 additions & 0 deletions github-archive-repos.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    require 'rubygems'
    require 'bundler/setup'
    require 'octokit'
    require 'active_support/core_ext'

    USERNAME = ''
    LOGIN = ''
    TOKEN = ''

    def client
    @client ||= Octokit::Client.new(:login => LOGIN, :token => TOKEN)
    end

    def repositories
    @repositories ||= client.repositories(USERNAME, :private => true)
    end

    def expired?(repo, ttl = 12.month)
    client.branches(repo).each do |branch|
    if DateTime.now.to_i - client.commits(repo, branch.first, :page => 1).first.committed_date.to_datetime.to_i < ttl
    return false
    end
    end

    true
    end

    repositories.each do |repo|
    puts repo.name if repo.private? && expired?(repo)
    end