Created
August 30, 2023 18:22
-
-
Save chtzvt/50af04ed08a709693a6df4903fe00147 to your computer and use it in GitHub Desktop.
Deletes all repositories associated with a given GitHub organization.
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 '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