Created
January 4, 2017 23:58
-
-
Save nicklewis/9580f909edc79e04b5e21c0415227169 to your computer and use it in GitHub Desktop.
Generate a dot graph of the blocking relationships between all the tickets in a set of epics
This file contains 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
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'json' | |
raise "Specify at least one epic" if ARGV.empty? | |
def make_request(client, url) | |
request = Net::HTTP::Get.new(url) | |
request.basic_auth ENV['JIRA_USERNAME'], ENV['JIRA_PASSWORD'] | |
response = client.request(request) | |
result = JSON.parse(response.body) | |
if result['errorMessages'] | |
raise result['errorMessages'].first | |
else | |
result | |
end | |
end | |
def retrieve_tickets(client, epics, offset=0) | |
STDERR.puts "Getting tickets at offset #{offset}" | |
result = make_request(client, URI.escape("/rest/api/2/search?startAt=#{offset}&jql='epic link' in (#{epics.join(',')})")) | |
total = result['total'] | |
max_results = result['maxResults'] | |
if offset + max_results < total | |
result['issues'] + retrieve_tickets(client, epics, offset + max_results) | |
else | |
result['issues'] | |
end | |
end | |
def print_ticket_to_dot(ticket, verbose=true) | |
if verbose | |
puts %Q|"#{ticket['key']}" [label="#{ticket['key']} #{ticket['fields']['summary'].gsub('"', '\"')}"];| | |
else | |
puts %Q|"#{ticket['key']}";| | |
end | |
ticket['fields']['issuelinks'].select {|link| link['type']['outward'] == 'blocks' && link['outwardIssue']}.each do |link| | |
puts %Q|"#{ticket['key']}" -> "#{link['outwardIssue']['key']}";| | |
end | |
end | |
short = ARGV.delete('--short') | |
epics = ARGV.dup | |
http = Net::HTTP.new('tickets.puppetlabs.com', 443) | |
http.use_ssl = true | |
tickets = retrieve_tickets(http, epics) | |
puts "digraph {" | |
tickets.each {|ticket| print_ticket_to_dot(ticket, !short)} | |
puts "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment