3 # Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 import urllib2, json, sys, string
20 from argparse import ArgumentParser
22 DESCRIPTION="update release changes"
24 ISSUE_URL= "https://dev.icinga.org/issues/"
27 arg_parser = ArgumentParser(description= "%s (Version: %s)" % (DESCRIPTION, VERSION))
28 arg_parser.add_argument('-V', '--version', required=True, type=str, help="define version to query")
29 arg_parser.add_argument('-p', '--project', type=str, help="add urls to issues")
30 arg_parser.add_argument('-l', '--links', action='store_true', help="add urls to issues")
31 arg_parser.add_argument('-H', '--html', action='store_true', help="print html output (defaults to markdown)")
33 args = arg_parser.parse_args(sys.argv[1:])
35 ftype = "md" if not args.html else "html"
37 def format_header(text, lvl, ftype = ftype):
39 return "<h%s>%s</h%s>" % (lvl, text, lvl)
41 return "#" * lvl + " " + text
43 def format_logentry(log_entry, args = args, issue_url = ISSUE_URL):
46 return "<li> {0} <a href=\"{4}{1}\">{1}</a> ({2}): {3}</li>".format(log_entry[0], log_entry[1], log_entry[2], log_entry[3],issue_url)
48 return "* {0} [{1}]({4}{1} \"{0} {1}\") ({2}): {3}".format(log_entry[0], log_entry[1], log_entry[2], log_entry[3], issue_url)
51 return "<li>%s %d (%s): %s</li>" % log_entry
53 return "* %s %d (%s): %s" % log_entry
55 def print_category(category, entries):
58 print format_header(category, 4)
63 for entry in sorted(entries):
64 print format_logentry(entry)
71 version_name = args.version
74 ISSUE_PROJECT=args.project
76 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
77 versions_data = json.loads(rsp.read())
81 for version in versions_data["versions"]:
82 if version["name"] == version_name:
83 version_id = version["id"]
86 if version_id == None:
87 print "Version '%s' not found." % (version_name)
92 if "custom_fields" in version:
93 for field in version["custom_fields"]:
95 changes = field["value"]
98 changes = string.join(string.split(changes, "\r\n"), "\n")
100 print format_header("What's New in Version %s" % (version_name), 3)
104 print format_header("Changes", 4)
116 # We could filter using &cf_13=1, however this doesn't currently work because the custom field isn't set
117 # for some of the older tickets:
118 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/issues.json?offset=%d&status_id=closed&fixed_version_id=%d" % (ISSUE_PROJECT, offset, version_id))
119 issues_data = json.loads(rsp.read())
120 issues_count = len(issues_data["issues"])
121 offset = offset + issues_count
123 if issues_count == 0:
126 for issue in issues_data["issues"]:
129 if "custom_fields" in issue:
130 for field in issue["custom_fields"]:
131 if field["id"] == 13 and "value" in field and field["value"] == "0":
138 if "category" in issue:
139 category = issue["category"]["name"]
141 category = "no category"
143 # the order is important for print_category()
144 entry = (issue["tracker"]["name"], issue["id"], category, issue["subject"].strip())
146 if issue["tracker"]["name"] == "Feature":
147 features.append(entry)
148 elif issue["tracker"]["name"] == "Bug":
149 bugfixes.append(entry)
150 elif issue["tracker"]["name"] == "Support":
151 support.append(entry)
153 print_category("Feature", features)
154 print_category("Bugfixes", bugfixes)
155 print_category("Support", support)