Created
February 18, 2014 14:26
-
-
Save yfujiki/9072022 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'optparse' | |
require 'pivotal-tracker' | |
TOKEN = 'YOUR_PIVOTAL_TOKEN' | |
PROJECT_IDS = [YOUR_PIVOTAL_PROJECT_ID] | |
TESTER_NAME = 'YOUR DEFAULT TESTER NAME (IF ANY)' | |
PivotalTracker::Client.token = TOKEN | |
def generate_options | |
options = { | |
:state => "finished", | |
:deliver => false, | |
:deliver_to => TESTER_NAME, | |
:created_since => nil, | |
:modified_since => nil | |
} | |
OptionParser.new do |o| | |
o.banner = "USAGE: #{$0} [options]" | |
o.on("-s", | |
"--state [STATE]", | |
"State to filter out : started, finished, delivered, accepted, rejected, etc...") do |s| | |
options[:state] = s.downcase | |
end | |
o.on("-d", | |
"--deliver [DELIVER_TO]", | |
"Name of a person you want to deliver this story to") do |d| | |
options[:deliver] = true | |
options[:deliver_to] = (d && d.length > 0) ? d.downcase : options[:deliver_to] | |
end | |
o.on("-r", | |
"--remove-review") do |r| | |
options[:remove_review] = true | |
end | |
o.on("-l", | |
"--label 'label1,label2'", | |
"Label") do |l| | |
options[:label] = l | |
end | |
o.on("-c", | |
"--created [CREATED_SINCE IN MM/DD/YYYY]", | |
"Created date of a story") do |c| | |
options[:created_since] = c | |
end | |
o.on("-m", | |
"--modified [MODIFIED_SINCE IN MM/DD/YYYY]", | |
"Modified date of a story") do |m| | |
options[:modified_since] = m | |
end | |
o.on("-v", | |
"--verbose") do |v| | |
options[:verbose] = true | |
end | |
o.on("-h", "--help", "Show help documentation") do |h| | |
puts o | |
exit | |
end | |
end.parse! | |
options | |
end | |
def generate_filter_options (options = {}) | |
filter_options = {} | |
if(options[:state] && options[:state] != "all") | |
filter_options[:state] = options[:state] | |
end | |
if(options[:created_since]) | |
filter_options[:created_since] = options[:created_since] | |
end | |
if(options[:modified_since]) | |
filter_options[:modified_since] = options[:modified_since] | |
end | |
if(options[:label]) | |
filter_options[:label] = options[:label] | |
end | |
filter_options | |
end | |
options = generate_options | |
filter_options = generate_filter_options options | |
PROJECT_IDS.each do |project_id| | |
project = PivotalTracker::Project.find(project_id) | |
project.stories.all(filter_options).each do |s| | |
if(options[:verbose]) | |
puts "Title : #{s.name}" | |
puts " Description : #{s.description.gsub(/\n+/,' ')}" | |
puts " Labels : #{s.labels}" | |
puts " Owner : #{s.owned_by}" | |
puts "" | |
else | |
puts s.name | |
end | |
if(options[:deliver]) | |
s.update({:current_state => "delivered", :owned_by => options[:deliver_to]}) | |
end | |
if(options[:remove_review]) | |
if(s.labels) | |
labels = s.labels.gsub(/(needs-review,?|code-review,?)/, '') | |
s.update({:labels => labels}) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment