如何使用ruby以编程方式删除Rally回收站中的缺陷?

时间:2013-03-27 17:41:20

标签: ruby rally bin recycle

我可以使用Ruby脚本和Rally Rest API删除Rally v12.4中的缺陷。然后,缺陷进入回收站。如何完全删除它?

如果您必须知道......我正在从ClearQuest导入数据(使用Enterprise editino并且没有CQ连接器)。当我完成映射时,我导入一个小批量来检查它是如何工作的。我重复这一点,但希望每次都清除所有缺陷。我编写了一个Ruby脚本来删除它们,但它不会从回收站中清除它们,而且必须逐个完成。一旦我迁移了数百个ClearQuest票证但发现了问题,我不想一个一个地从回收站中删除它们。

同样,要回答的问题是,“如何完全删除它?”

1 个答案:

答案 0 :(得分:0)

以下脚本可能有助于完成此任务:

# 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