-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_pull.rb
96 lines (82 loc) · 3.05 KB
/
query_pull.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
require 'rest-client'
require 'json'
# here is our jira instance
project_key = 'ABC'
jira_url = 'https://simp-project.atlassian.net/rest/api/2/search?'
# find current sprint
filter = "jql=\"Parent Link\"=SIMP-6063"
# set a max # results - defaults to 50 (we can switch this to a loop later)
total_issues = 1
ticket_count = 0
maxresults = 50
# while we have tickets still
while ticket_count < total_issues
# call the code
newfilter = "#{filter}&maxResults=#{maxresults}&startAt=#{ticket_count}"
response = RestClient.get(jira_url + newfilter)
raise 'Error with the http request!' if response.code != 200
data = JSON.parse(response.body)
# puts "current data is #{data}"
# find the number of tickets returned
total_issues = data['total']
data['issues'].each do |issue|
points = issue['fields']['customfield_10005']
points = points.to_i
issuekey = issue['key']
summary = issue['fields']['summary']
desc = issue['fields']['description']
# substitute apostrophe for quote
unless desc.nil?
temp = desc.tr('"', "\'")
desc = temp
end
# see if it has a parent, and if so, display it"
parent = if !issue['fields']['parent'].nil?
issue['fields']['parent']['key']
else
"#{issuekey}."
end
# calculate the sprint by breaking the "sprint=" out of the sprint attributes string
sprintdata = issue['fields']['customfield_10007']
if sprintdata != nil
idstring = sprintdata[0]
idstringname = idstring.slice(idstring.index('name='), idstring.size)
comma = idstringname.index(',') - 1
sprintid = idstringname[5..comma]
else
sprintid = ''
end
# get type
issuetype = if !issue['fields']['issuetype'].nil?
issue['fields']['issuetype']['name']
else
''
end
# get assignee
assignee = if !issue['fields']['assignee'].nil?
issue['fields']['assignee']['name']
else
''
end
# get fixver
if (issue['fields']['fixVersions'].length > 0) then
fixverstring = issue['fields']['fixVersions'][0]
fixver = fixverstring['name']
else
fixver = ''
end
# if this is the first output, then open the file with the sprintname and write the header
if (ticket_count == 0) then
# first create two .csv files - one with the parent appended, the other without - ensure the field names are OK
filesprint = sprintid.gsub(" ","_")
filesprint = filesprint.gsub("__","_")
pullfile = "query_pull.csv"
$parentpullfile = File.open(pullfile, 'w')
$parentpullfile.puts('Issue id,Parent id,Summary,Issue Type,Story Points,Sprint,Description,Assignee,Fix Version')
end
# write to files
$parentpullfile.puts("#{issuekey},#{parent},\"#{parent}/#{summary} (#{issuekey})\",#{issuetype},#{points},#{sprintid},\"#{desc}\",#{assignee},#{fixver}")
ticket_count = ticket_count + 1
end # while there are still tickets
puts "ticket count is #{ticket_count}"
end