2 #/******************************************************************************
4 # * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
6 # * This program is free software; you can redistribute it and/or *
7 # * modify it under the terms of the GNU General Public License *
8 # * as published by the Free Software Foundation; either version 2 *
9 # * of the License, or (at your option) any later version. *
11 # * This program is distributed in the hope that it will be useful, *
12 # * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 # * GNU General Public License for more details. *
16 # * You should have received a copy of the GNU General Public License *
17 # * along with this program; if not, write to the Free Software Foundation *
18 # * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 # ******************************************************************************/
21 import urllib2, json, sys, string
22 from argparse import ArgumentParser
24 DESCRIPTION="update release changes"
26 ISSUE_URL= "https://dev.icinga.org/issues/"
29 arg_parser = ArgumentParser(description= "%s (Version: %s)" % (DESCRIPTION, VERSION))
30 arg_parser.add_argument('-V', '--version', required=True, type=str, help="define version to query")
31 arg_parser.add_argument('-p', '--project', type=str, help="add urls to issues")
32 arg_parser.add_argument('-l', '--links', action='store_true', help="add urls to issues")
33 arg_parser.add_argument('-H', '--html', action='store_true', help="print html output (defaults to markdown)")
35 args = arg_parser.parse_args(sys.argv[1:])
37 ftype = "md" if not args.html else "html"
39 def format_header(text, lvl, ftype = ftype):
41 return "<h%s>%s</h%s>" % (lvl, text, lvl)
43 return "#" * lvl + " " + text
45 def format_logentry(log_entry, args = args, issue_url = ISSUE_URL):
48 return "<li> {0} <a href=\"{3}{1}\">{1}</a>: {2}</li>".format(log_entry[0], log_entry[1], log_entry[2], issue_url)
50 return "* {0} [{1}]({3}{1} \"{0} {1}\"): {2}".format(log_entry[0], log_entry[1], log_entry[2], issue_url)
53 return "<li>%s %d: %s</li>" % log_entry
55 return "* %s %d: %s" % log_entry
57 def print_category(category, entries):
60 print format_header(category, 4)
65 for entry in sorted(entries):
66 print format_logentry(entry)
73 version_name = args.version
76 ISSUE_PROJECT=args.project
78 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
79 versions_data = json.loads(rsp.read())
83 for version in versions_data["versions"]:
84 if version["name"] == version_name:
85 version_id = version["id"]
88 if version_id == None:
89 print "Version '%s' not found." % (version_name)
94 if "custom_fields" in version:
95 for field in version["custom_fields"]:
97 changes = field["value"]
100 changes = string.join(string.split(changes, "\r\n"), "\n")
102 print format_header("What's New in Version %s" % (version_name), 3)
106 print format_header("Changes", 4)
118 # We could filter using &cf_13=1, however this doesn't currently work because the custom field isn't set
119 # for some of the older tickets:
120 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))
121 issues_data = json.loads(rsp.read())
122 issues_count = len(issues_data["issues"])
123 offset = offset + issues_count
125 if issues_count == 0:
128 for issue in issues_data["issues"]:
131 if "custom_fields" in issue:
132 for field in issue["custom_fields"]:
133 if field["id"] == 13 and "value" in field and field["value"] == "0":
140 entry = (issue["tracker"]["name"], issue["id"], issue["subject"].strip())
142 if issue["tracker"]["name"] == "Feature":
143 features.append(entry)
144 elif issue["tracker"]["name"] == "Bug":
145 bugfixes.append(entry)
146 elif issue["tracker"]["name"] == "Support":
147 support.append(entry)
149 print_category("Feature", features)
150 print_category("Bugfixes", bugfixes)
151 print_category("Support", support)