【问题标题】:How do I programmatically delete a defect in the Rally recycle bin using ruby?如何使用 ruby 以编程方式删除 Rally 回收站中的缺陷?
【发布时间】:2023-03-12 01:05:01
【问题描述】:
我可以使用 Ruby 脚本和 Rally Rest API 删除 Rally v12.4 中的缺陷。然后缺陷进入回收站。如何彻底删除?
如果您必须知道...我正在从 ClearQuest 导入数据(使用 Enterprise editino 并且没有 CQ 连接器)。当我处理映射时,我导入了一小批来检查它是如何工作的。我重复这一点,但每次都想清除所有缺陷。我写了一个 Ruby 脚本来删除它们,但它不会从回收站中清除它们,而且必须一个接一个地完成。一旦我迁移了数百张 ClearQuest 票证但发现问题,我不想将它们从回收站中一个一个地删除。
同样,要回答的问题是,“我如何完全删除它?”
【问题讨论】:
标签:
ruby
rally
bin
recycle
【解决方案1】:
以下脚本可能有助于完成此任务:
# 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