DEV Community

Ankit Chachada
Ankit Chachada

Posted on

Deleting repositories using Octokit

I was trying to delete a few repositories from my GitHub account which had issues, but deleting one by one was cumbersome. Also, every time when you have to delete the repository, you have to type the repository name. So I googled and I found an amazing ruby gem octokit which helped me to delete the selected repositories. I would really love to get feedback on my code.

require 'octokit'

client = Octokit::Client.new(:login => 'USERNAME',
                             :password => 'PASSWORD')
repo_hash = {}
client.repositories('USERNAME').each do |i|
 repo_hash[i["id"]] = i["name"] #collecting ID as key and name as value
end

#array of repositories I wanted to delete
repos = ["ABC","XYZ","PQR"]

del_repos = []
repos.each do |repo|
  del_repos << repo_hash.key(repo) #delete_repository needs ID 
end

del_repos.each do |i|
  client.delete_repository(i)
end

Top comments (0)