Skip to content

Instantly share code, notes, and snippets.

@aterreno
Created September 19, 2014 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aterreno/e52ffecd6e0ae9679b0a to your computer and use it in GitHub Desktop.
Save aterreno/e52ffecd6e0ae9679b0a to your computer and use it in GitHub Desktop.
Calculating cycle times with ruby
require 'rubygems'
require 'jira'
require 'date'
require 'time_difference'
require 'pp'
def time_diff(statuses, tstart, tend)
begin
TimeDifference.between(statuses[tstart], statuses[tend]).in_days
rescue Exception => e
$stderr.puts "failed diffing: #{tstart} - #{tend}"
$stderr.puts tstart
$stderr.puts tend
-1
end
end
options = {
:username => "antonio.terreno",
:password => "",
:site => '',
:context_path => '/',
:auth_type => :basic
}
client = JIRA::Client.new(options)
project = client.Project.find('DCJ')
proprieties = %w[Key Summary]
states = %w[Backlog Soon Next In\ Progress In\ test Ready\ to\ amaze Withdrawn]
puts (proprieties + states).join("\t")
client.Issue.jql('PROJECT = DCJ ORDER BY KEY DESC', options = {fields: ['key','summary','changelog'], start_at: 1000, max_results: 1000}).each do |issue|
issue = client.Issue.find(issue.key, {expand:'changelog'})
statuses = Hash.new
results = Hash.new
issue.changelog["histories"].each do |history|
history["items"].select {|item| item["field"] == 'status'}.each do |item|
key = item["fromString"] + "->" + item["toString"]
value = Time.parse(history["created"])
statuses[key] = value
end
end
$stderr.puts issue.key
$stderr.puts statuses.keys
results["Ready to amaze"] = time_diff(statuses,"Ready To Amaze->Amazing","In Test->Ready To Amaze")
results["In test"] = time_diff(statuses,"In Test->Ready To Amaze" ,"In Progress->In Test")
results["In Progress"] = time_diff(statuses, "In Progress->In Test" , "Next->In Progress")
results["Next"] = time_diff(statuses, "Next->In Progress" , "Soon->Next")
results["Soon"] = time_diff(statuses, "Soon->Next" , "Withdrawn->Soon")
results["Withdrawn"] = time_diff(statuses, "Withdrawn->Soon" , "Soon->Withdrawn")
results["Backlog"] = time_diff(statuses, "Soon->Withdrawn" , "Backlog->Soon")
print "#{issue.key}\t#{issue.summary}\t"
states.each do |state|
print "#{results[state]}\t"
end
print "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment