video-iac/scripts/delete-gitea-repos.rb

45 lines
1.1 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env ruby
require 'net/http'
require 'json'
require 'uri'
# Configuration
GITEA_URL = "https://git.staging.jamkazam.com/api/v1"
GITEA_TOKEN = "6798c2d2b1beed9a8c33c738f7a521548e40bcc5"
GITEA_OWNER = "seth"
# Default repos if none specified
DEFAULT_REPOS = ["jam-cloud", "video-iac"]
repos_to_delete = ARGV.empty? ? DEFAULT_REPOS : ARGV
def delete_repo(repo_name)
puts "🗑️ Deleting repository: #{repo_name}..."
uri = URI.parse("#{GITEA_URL}/repos/#{GITEA_OWNER}/#{repo_name}")
header = {
'Authorization' => "token #{GITEA_TOKEN}"
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri, header)
response = http.request(request)
if response.code == "204"
puts "✅ Successfully deleted #{repo_name}."
elsif response.code == "404"
puts " Repository #{repo_name} not found. Skipping."
else
puts "❌ Failed to delete #{repo_name}: #{response.code}"
puts response.body
end
end
repos_to_delete.each do |repo|
delete_repo(repo)
end
puts "\n✨ Cleanup complete."