-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathbuild_releasenotes.rb
233 lines (169 loc) · 5.74 KB
/
build_releasenotes.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
require 'rubygems'
require 'pp'
require 'jira-ruby'
require 'getoptlong'
require 'fileutils'
class Releasenotes
def initialize(esversion, sgversion)
@esversion = esversion
@sgversion = sgversion
versionAsInt = @sgversion.gsub(/\./, '').to_i
@order = 4700 - versionAsInt
@rn_field = "customfield_11326"
puts "Building changelogs for ES version #{esversion} and SG version #{sgversion}"
options = {
:username => ENV['JIRA_USERNAME'],
:password => ENV['JIRA_API_KEY'],
:site => 'https://floragunn.atlassian.net/',
:context_path => '',
:auth_type => :basic
}
@client = JIRA::Client.new(options)
@issueTypes = {
"New Feature" => "New Features",
"Improvement" => "Improvements",
"Bug" => "Bug Fixes",
"Security Issue" => "Security Fixes",
"Documentation" => "Documentation",
"Task" => "Other"
}
end
def generate
core_epics = fetch_epics("Search Guard Core")
kibana_epics = fetch_epics("Search Guard Kibana Plugin")
puts "Fetched Search Guard Core Epics:"
core_epics.each { |epicKey, epicName|
puts "#{epicKey} - #{epicName}"
}
puts "Fetched Search Guard Kibana Plugin Epics:"
kibana_epics.each { |epicKey, epicName|
puts "#{epicKey} - #{epicName}"
}
generate_changelog(core_epics, true)
generate_changelog(kibana_epics, false)
end
def fetch_epics(productname)
epics_map = Hash.new
epics = @client.Issue.jql("project = SGD AND issuetype = Epic AND status = \"To Do\" AND Product = \"#{productname}\" ORDER BY issuekey ASC", max_results: 500)
epics.each do |epic|
epics_map[epic.key] = epic.summary
end
return epics_map
end
def generate_changelog (epics, isCore)
filename = "./_content/_changelogs/changelog_#{isCore ? 'searchguard' : 'kibana'}_#{@esversion}_x_#{@sgversion.gsub(/\./, '_')}.md"
# remove previous version
FileUtils.rm_f(filename)
puts filename
file = File.new(filename, 'a')
generate_file_header(file, isCore)
generate_changelog_entries(file, epics)
ensure
file.close
end
def generate_file_header (file, isCore)
t = Time.now
pluginName = isCore ? "Search Guard" : "Kibana"
pluginNameLower = isCore ? "searchguard" : "kibana"
file.write("---\n")
file.write("title: #{pluginName} #{@esversion}.x-#{@sgversion}\n")
file.write("slug: changelog-#{pluginNameLower}-#{@esversion}.x-#{@sgversion.gsub(/\./, '_')}\n")
file.write("category: changelogs-#{pluginNameLower}\n")
file.write("order: #{@order}\n")
file.write("layout: changelogs\n")
file.write("description: Changelog for #{pluginName} #{@esversion}.x-#{@sgversion} \n")
file.write("---\n\n")
file.write("<!--- Copyright #{t.year} floragunn GmbH -->\n\n")
file.write("**Release Date: #{t.strftime("%d.%m.%Y")}**\n\n")
file.write("* [Upgrade Guide from 6.x to 7.x](../_docs_installation/installation_upgrading_6_7.md)\n\n")
end
def generate_changelog_entries (file, epics)
version = "SG#{@esversion} #{@sgversion}"
@issueTypes.each { |issueType, issueTypeDisplayName|
holder = Hash.new
epics.each { |epicKey, epicName|
issuesByTypeAndEpic = fetchIssues(version, epicKey, epicName, issueType)
puts "Found #{issuesByTypeAndEpic.length} issues for type #{issueType} and epic #{epicName}" unless issuesByTypeAndEpic.nil?
puts "Found no issued for #{issuesByTypeAndEpic.length} for type #{issueType} and epic #{epicName}" if issuesByTypeAndEpic.nil?
unless issuesByTypeAndEpic.nil? || issuesByTypeAndEpic.empty?
holder[epicName] = issuesByTypeAndEpic
end
}
# render section if we have any issues in this category
unless holder.empty?
generate_issues_for_type(file, issueTypeDisplayName, holder)
end
}
end
def generate_issues_for_type(file, issueTypeDisplayName, holder)
file.write("## #{issueTypeDisplayName}\n\n")
holder.each { |epicName, issues|
file.write("\n\n")
file.write("### #{epicName}\n\n")
issues.each do |issue|
level = 0
# RN field, honor new lines
rnotes = issue.fields['customfield_11326']
unless rnotes.nil?
rnotes.split("\n").each do |linernote|
indentation = level == 0 ? "* " : " * "
file.write("#{indentation}#{linernote}\n") unless linernote.blank?
level += 1
end
end
file.write ("<p />\n")
end
}
file.write("\n\n")
end
def fetchIssues(version, epicKey, epicName, issueType)
query = "fixVersion=\"#{version}\" AND project=\"SGD\" AND status=Done AND \"Epic Link\" = \"#{epicKey}\" AND type = \"#{issueType}\" AND \"Release Notes\" IS NOT EMPTY ORDER BY issuekey DESC "
issues = @client.Issue.jql(query, max_results: 500)
return issues
end
end
esversion = nil
sgversion = nil
help = false
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--esversion', '-e', GetoptLong::REQUIRED_ARGUMENT ],
[ '--sgversion', '-s', GetoptLong::REQUIRED_ARGUMENT ]
)
opts.each do |opt, arg|
case opt
when '--help'
help = true
puts <<-EOF
./build_releasenptes.rb [OPTION]
-h, --help:
show help
--esversion, -e:
The major version of Elasticsearch / Kbana
--sgversion, -s:
The release version as used in JIRA
You need to set the following environment variables:
JIRA_USERNAME: The JIRA username
JIRA_API_KEY: The API key to use with this username
EOF
when '--esversion'
esversion = arg
when '--sgversion'
sgversion = arg
end
end
if help
exit 0
end
if !esversion
puts "Missing --esversion argument (try --help)"
puts 'Example: ruby build_releasenotes.rb -e 7 -s 41.0.0'
exit 0
end
if !sgversion
puts "Missing --sgversion argument (try --help)"
puts 'Example: ruby build_releasenotes.rb -e 7 -s 41.0.0'
exit 0
end
rn = Releasenotes.new(esversion, sgversion)
rn.generate()