Skip to content

Instantly share code, notes, and snippets.

@chtzvt
Created August 30, 2023 18:22
Show Gist options
  • Save chtzvt/50af04ed08a709693a6df4903fe00147 to your computer and use it in GitHub Desktop.
Save chtzvt/50af04ed08a709693a6df4903fe00147 to your computer and use it in GitHub Desktop.
Deletes all repositories associated with a given GitHub organization.
require 'octokit'
access_token = ENV["GH_PAT"]
org_name = ENV["GH_ORG"]
begin
client = Octokit::Client.new(access_token: access_token)
rescue Octokit::Unauthorized
puts "Invalid access token. Please set the GH_PAT environment variable to a valid GitHub Personal Access Token."
exit
end
puts "This script will delete all repositories in the organization #{org_name}."
puts "Are you sure you want to proceed? (yes/no)"
confirmation = gets.chomp.downcase
if confirmation == "yes"
repositories = client.org_repos(org_name)
repositories.each do |repo|
puts "Deleting #{repo.full_name}..."
client.delete_repository(repo.full_name)
puts "#{repo.full_name} deleted."
end
else
puts "Operation canceled."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment