forked from RallyTools/Rally-Recycle-Bin-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rally_recyclebin_report.rb
123 lines (89 loc) · 3.89 KB
/
rally_recyclebin_report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2002-2013 Rally Software Development Corp. All Rights Reserved.
#
# This script is open source and is provided on an as-is basis. Rally provides
# no official support for nor guarantee of the functionality, usability, or
# effectiveness of this code, nor its suitability for any application that
# an end-user might have in mind. Use at your own risk: user assumes any and
# all risk associated with use and implementation of this script in his or
# her own environment.
# Usage: ruby rally_recyclebin_report.rb
# Specify the User-Defined variables below. Script will iterate through all items in
# Rally Recycle bin and summarize their properties
require 'rally_api'
require 'csv'
$my_base_url = "https://rally1.rallydev.com/slm"
$my_username = "[email protected]"
$my_password = "password"
$my_workspace = "My Workspace"
# jt - change $wsapi_version to "v2.0"
# $wsapi_version = "1.43"
$wsapi_version = "v2.0"
$my_output_file = "recyclebin.csv"
$recyclebin_fields = %w{FormattedID ObjectID DeletionDate Name DeletedBy Type Ref RestoreLink}
if $my_delim == nil then $my_delim = "," end
# Make no edits below this line!!
# =================================
#Setting custom headers
$headers = RallyAPI::CustomHttpHeader.new()
$headers.name = "Rally Recycle Bin Report"
$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[:version] = $wsapi_version
config[:headers] = $headers
@rally = RallyAPI::RallyRestJson.new(config)
# Query for all Recycle Bin Items
recycle_bin_query = RallyAPI::RallyQuery.new()
# jt - change type to recyclebinentry
# recycle_bin_query.type = :recyclebin
recycle_bin_query.type = :recyclebinentry
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 output to summary file."
puts "Start processing items..."
# Loop through matching artifacts and summarize them.
# Output CSV header
recyclebin_csv = CSV.open($my_output_file, "w", {:col_sep => $my_delim})
recyclebin_csv << $recyclebin_fields
# Loop through recycle bin entries and output them
puts "Exporting recycle bin items to file: #{$my_output_file}."
puts "Total Items to Export: #{number_recycle_bin_items}"
exported_count = 0
recycle_bin_query_results.each do | this_recycle_bin_item |
data = []
exported_count += 1
item_id = this_recycle_bin_item["ID"]
item_oid = this_recycle_bin_item["ObjectID"]
item_deletion_date = this_recycle_bin_item["DeletionDate"]
item_name = this_recycle_bin_item["Name"]
item_deleted_by = this_recycle_bin_item["DeletedBy"]._refObjectName
item_type = this_recycle_bin_item["Type"]
item_ref = this_recycle_bin_item["_ref"]
item_restore_link = "#{$my_base_url}/recyclebin/restore.sp?oid=#{item_oid}"
data << item_id
data << item_oid
data << item_deletion_date
data << item_name
data << item_deleted_by
data << item_type
data << item_ref
data << item_restore_link
recyclebin_csv << CSV::Row.new($recyclebin_fields, data)
end
puts
puts "Summarized a total of #{exported_count} items in the Recycle Bin."
puts "Complete!"
end