Last active
July 6, 2019 13:06
-
-
Save diraulo/442861f1c814c7738fc13c464442090c to your computer and use it in GitHub Desktop.
Interactively delete forked repositories on GitHub
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
# frozen_string_literal: true | |
require "octokit" | |
require "awesome_print" | |
# Generate a token with delete_repo scope here https://github.com/settings/tokens/new | |
ACCESS_TOKEN = "your_personal_access_token" | |
begin | |
client = Octokit::Client.new(access_token: ACCESS_TOKEN) | |
client.auto_paginate = true | |
forked_repos = client.repositories(client.user.login) | |
.select { |repo| repo.fork == true } | |
puts "#{forked_repos.count} forked repositories" | |
forked_repos.each do |repo| | |
puts """ | |
Name: #{repo.full_name} | |
Description: #{repo.description} | |
Fork?: #{repo.fork} | |
🤔 Do you want to delete this repository (y/n)?: | |
""" | |
next unless gets.chomp == "y" | |
begin | |
puts "❌ Deleting #{repo.full_name}..." | |
client.delete_repository(repo.full_name) | |
puts "✅ Done" | |
rescue StandardError => error | |
puts "☹️ Couldn't delete the repository:" | |
ap error | |
end | |
end | |
rescue Octokit::Unauthorized => error | |
puts "🤯 Something has gone terribly wrong \n #{error}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment