Skip to content

Instantly share code, notes, and snippets.

@afeld afeld/README.md
Last active Dec 17, 2018

Embed
What would you like to do?
archive inactive GitHub repositories in an organization
  1. Install Ruby.

  2. Create a token.

  3. Install the dependencies.

    gem install activesupport octokit
  4. Run the script.

    ORG=... GITHUB_TOKEN=... ruby archive.rb

Creative Commons Zero - public domain

require 'active_support'
require 'active_support/core_ext/numeric'
require 'octokit'
TOKEN = ENV.fetch('GITHUB_TOKEN')
client = Octokit::Client.new(access_token: TOKEN)
client.auto_paginate = true
ORG = ENV.fetch('ORG')
CUTOFF = ENV.fetch('CUTOFF_DAYS', '90').to_i.days.ago
repos = client.organization_repositories(ORG)
repos.each do |repo|
if repo.archived
next
end
# always archive "DEPRECATED" repositories
description = repo.description || ""
unless description.match?(/DEPRECATED/i)
# if anything has happened with the repository since the CUTOFF, skip it
if repo.updated_at > CUTOFF || repo.pushed_at > CUTOFF
next
end
events = client.repository_events(repo.full_name, per_page: 1)
latest_event = events.first
if latest_event && latest_event.created_at > CUTOFF
next
end
end
print "Archiving #{repo.name} ... "
client.edit_repository(repo.full_name, archived: true)
puts "done"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.