Created
April 15, 2015 14:55
-
-
Save krishnan-mani/4616ee210a45a89da7ce to your computer and use it in GitHub Desktop.
List inactive repositories for the organisation
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
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 |
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
This script is awesome. Thank you so much.
I have a question, what if I dont want to enter details manually and add them directly in script. What changes do i need to make?
@aterreno @krishnan-mani