Last active
September 1, 2017 03:02
-
-
Save goodfeel/8ef8a2023d88c19c936807a8eaaa9015 to your computer and use it in GitHub Desktop.
Mass Delete Bitbucket Repo via API
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
# You need to create Oauth consumer app here: | |
# https://bitbucket.org/account/user/<Your BB username>/api | |
# Or go to Bitbucket and Click no your user and click on BitBucket Settings | |
# Get the token by access: | |
# https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code | |
# On the URL Query string you should see the code | |
# Run curl -X POST -u "<OAuth App ID>:<OAuth App Secret>" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code=<Code from previous step> | |
# Then you should get your token and replace that in the code. Don't forget to keep refresh token in case, you want to refresh it. | |
# Refresh: | |
# curl -X POST -u "<OAuth App ID>:<OAuth App Secret>" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d 'refresh_token=<Refresh Token>' | |
require 'uri' | |
require 'net/http' | |
require 'openssl' | |
# path to the txt file with one repo name per line. | |
filename = "app.txt" | |
File.foreach(filename).with_index do |line, line_num| | |
puts "#{line}" | |
line.strip! | |
uri = URI.encode("https://api.bitbucket.org/2.0/repositories/<You Account Repo name here>/#{line}") | |
url = URI.parse(uri) | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Delete.new(url) | |
request["content-type"] = 'application/json' | |
request["authorization"] = 'Bearer <Bitbucket OAuth Token Here>' | |
request["cache-control"] = 'no-cache' | |
request.body = "{}" | |
response = http.request(request) | |
puts response.read_body | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment