以下脚本可能有助于完成此任务:
# Usage: ruby rally_empty_recycle_bin.rb
# Specify the User-Defined variables below. Script will iterate through all items in
# Rally Recycle bin for specified Workspace and Project, and prompt the user to confirm
# permanent deletion of the item of interest.
require 'rally_api'
$my_base_url = "https://rally1.rallydev.com/slm"
$my_username = "user@company.com"
$my_password = "password"
$my_workspace = "My Workspace"
$my_project = "My Project"
$wsapi_version = "1.41"
# Make no edits below this line!!
# =================================
#Setting custom headers
$headers = RallyAPI::CustomHttpHeader.new()
$headers.name = "Rally Empty Recycle Bin"
$headers.vendor = "Rally Labs"
$headers.version = "0.50"
# Load (and maybe override with) my personal/private variables from a file...
my_vars= File.dirname(__FILE__) + "/my_vars.rb"
if FileTest.exist?( my_vars ) then require my_vars end
begin
#==================== Make a connection to Rally ====================
config = {:base_url => $my_base_url}
config[:username] = $my_username
config[:password] = $my_password
config[:workspace] = $my_workspace
config[:project] = $my_project
config[:version] = $wsapi_version
config[:headers] = $headers
@rally = RallyAPI::RallyRestJson.new(config)
# Lookup source Test Folder
recycle_bin_query = RallyAPI::RallyQuery.new()
recycle_bin_query.type = :recyclebin
recycle_bin_query.fetch = true
recycle_bin_query_results = @rally.find(recycle_bin_query)
number_recycle_bin_items = recycle_bin_query_results.total_result_count
if number_recycle_bin_items == 0
puts "No items found in Recycle Bin. Exiting."
exit
end
puts "Found #{number_recycle_bin_items} items in Recycle Bin for possible deletion."
puts "Start processing deletions..."
# Loop through matching artifacts and delete them. Prompt user
# for each deletion.
number_processed = 0
number_deleted = 0
affirmative_answer = "Y"
recycle_bin_query_results.each do | this_recycle_bin_item |
number_processed += 1
puts "Processing deletion for item #{number_processed} of #{number_recycle_bin_items}."
item_formatted_id = this_recycle_bin_item["ID"]
item_name = this_recycle_bin_item["Name"]
item_type = this_recycle_bin_item["Type"]
puts "Deleting Item #{item_formatted_id}, #{item_type}: #{item_name}..."
puts this_recycle_bin_item["_ref"]
really_delete = [(print "Really delete? [Y/n]:"), gets.rstrip][1]
if really_delete == affirmative_answer then
begin
delete_result = @rally.delete(this_recycle_bin_item["_ref"])
puts "DELETED #{item_formatted_id}: #{item_name}"
puts delete_result
number_deleted += 1
rescue => ex
puts "Error occurred trying to delete: #{item_formatted_id}: #{item_name}"
puts ex.backtrace
end
else
puts "Did NOT delete #{item_formatted_id}: #{item_name}."
end
end
puts
puts "Deleted a total of #{number_deleted} items from the Recycle Bin."
puts "Complete!"
end