Skip to content

Instantly share code, notes, and snippets.

@krishnan-mani
Created April 15, 2015 14:55
Show Gist options
  • Save krishnan-mani/4616ee210a45a89da7ce to your computer and use it in GitHub Desktop.
Save krishnan-mani/4616ee210a45a89da7ce to your computer and use it in GitHub Desktop.
List inactive repositories for the organisation
require 'github_api'
require 'date'
puts 'You can obtain your access token from: https://github.com/settings/applications#personal-access-tokens'
puts 'Your Github.com access token:'
GITHUB_PERSONAL_ACCESS_TOKEN = gets.chomp
puts 'Your Github.com organisation:'
github_org = gets.chomp
puts 'Inactive for number of days in the past:'
number_of_days = gets.chomp.to_i
older_than_date = Date.today - number_of_days
github = Github.new oauth_token: GITHUB_PERSONAL_ACCESS_TOKEN
repos = github.repos.list org: github_org
limit_to_older_repos = repos.reject { |repo| Date.parse(repo.pushed_at) > older_than_date }
sorted_repos = limit_to_older_repos.sort_by { |repo| repo.pushed_at }
SEPARATOR = ','
unless sorted_repos.empty?
puts "Repository#{SEPARATOR}Last pushed at#{SEPARATOR}Clone from"
end
sorted_repos.each do |repo|
puts "#{repo.name}#{SEPARATOR}#{repo.pushed_at}#{SEPARATOR}#{repo.clone_url}"
end
@aterreno
Copy link

Wherever you read gets dot something you can replace with an hardcoded value.

GITHUB_PERSONAL_ACCESS_TOKEN = gets.chomp

Becomes

GITHUB_PERSONAL_ACCESS_TOKEN = "lalalayoursecrettoken"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment