-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira_pulls.rb
158 lines (139 loc) · 4.68 KB
/
jira_pulls.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require 'rest-client'
require 'json'
require 'fileutils'
require 'optparse'
days = 0
sprintno = ''
outputdir = ''
pullfile='test.csv'
optsparse = OptionParser.new do |opts|
opts.banner = "Usage: jira_pull [options] (default will pull only the current sprint)"
opts.on('-h', '--help', 'Help') do
puts opts
exit
end
opts.on('-s', '--sprint NUMBER', 'Sprint') do
|s| puts "sprint is #{s}"
sprintno = s.strip
end
opts.on('-d', '--closed since days', 'number of days (channges to closed query)') do
|d| puts "sprint is #{d}"
days = d.strip
pullfile = "closed_#{days}.csv"
end
opts.on('-o', '--output DIR', 'Output Dir (full path)') do
|o| puts "outdir is #{o}"
outputdir = o.strip
end
end
optsparse.parse!
# here is our jira instance
project_key = 'ABC'
jira_url = 'https://simp-project.atlassian.net/rest/api/2/search?'
# create query
if sprintno != ''
filter = "jql=sprint=#{sprintno}"
elsif days != 0
filter = "jql=resolved%3e%2d#{days}d%20and%20status=closed"
else
filter = 'jql=sprint%20in%20openSprints()'
end
puts "query is #{filter}"
# 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']
# substitute apostrophe for quote
unless summary.nil?
temp = summary.tr('"', "\'")
summary = temp
end
desc = issue['fields']['description']
# substitute apostrophe for quote
unless desc.nil?
temp = desc.tr('"', "\'")
desc = temp
end
# puts "issue is #{issue['id']} key is #{issue['key']}"
# see if it has a parent, and if so, display it"
parent = if !issue['fields']['parent'].nil?
issue['fields']['parent']['key']
else
"#{issuekey}."
end
# what is the status?
status = issue['fields']['status']['name']
# puts "status is #{status}"
# calculate the sprint by breaking the "sprint=" out of the sprint attributes string
sprintdata = issue['fields']['customfield_10007']
if sprintdata != nil
idstring = sprintdata[0]
sprintid = idstring['name']
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
# get component
if (issue['fields']['components'].length > 0) then
components = issue['fields']['components'][0]
component = components['name']
else
component = ''
end
# puts "component is #{component}"
# 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("__","_")
puts " old #{pullfile}"
if pullfile == 'test.csv'
pullfile = "currentpull#{filesprint}.csv"
end
puts " new #{pullfile}"
$parentpullfile = File.open(pullfile, 'w')
$parentpullfile.puts('Issue id,Parent id,Summary,Issue Type,Story Points,Sprint,Description,Assignee,Fix Version, Component, Status')
end
# write to files
$parentpullfile.puts("#{issuekey},#{parent},\"#{parent}/#{summary} (#{issuekey})\",#{issuetype},#{points},#{sprintid},\"#{desc}\",#{assignee},#{fixver},#{component},#{status}")
ticket_count = ticket_count + 1
end # while there are still tickets
puts "ticket count is #{ticket_count}"
end
# now that we are done, send the output file to the proper output directory
finalpullfile = "#{outputdir}#{pullfile}"
puts " old: #{pullfile}, new: #{finalpullfile}"
# FileUtils.cp($parentpullfile,finalpullfile)