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
58 version_name = args.version
61 ISSUE_PROJECT=args.project
63 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
64 versions_data = json.loads(rsp.read())
68 for version in versions_data["versions"]:
69 if version["name"] == version_name:
70 version_id = version["id"]
73 if version_id == None:
74 print "Version '%s' not found." % (version_name)
79 if "custom_fields" in version:
80 for field in version["custom_fields"]:
82 changes = field["value"]
85 changes = string.join(string.split(changes, "\r\n"), "\n")
87 print format_header("What's New in Version %s" % (version_name), 3)
91 print format_header("Changes", 4)
101 # We could filter using &cf_13=1, however this doesn't currently work because the custom field isn't set
102 # for some of the older tickets:
103 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))
104 issues_data = json.loads(rsp.read())
105 issues_count = len(issues_data["issues"])
106 offset = offset + issues_count
108 if issues_count == 0:
111 for issue in issues_data["issues"]:
114 if "custom_fields" in issue:
115 for field in issue["custom_fields"]:
116 if field["id"] == 13 and "value" in field and field["value"] == "0":
123 log_entries.append((issue["tracker"]["name"], issue["id"], issue["subject"].strip()))
128 for log_entry in log_entries:
129 if (p == 0 and log_entry[0] == "Feature") or (p == 1 and log_entry[0] != "Feature"):
133 print format_header("Features", 4) if p == 0 else format_header("Bugfixes", 4)
138 for log_entry in sorted(log_entries):
139 if (p == 0 and log_entry[0] == "Feature") or (p == 1 and log_entry[0] != "Feature"):
140 print format_logentry(log_entry)