]> granicus.if.org Git - icinga2/blob - changelog.py
Docs: Add SELinux chapter
[icinga2] / changelog.py
1 #!/usr/bin/env python
2 # Icinga 2
3 # Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)
4 #
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.
9 #
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.
14 #
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.
18
19 import urllib2, json, sys, string
20 from argparse import ArgumentParser
21
22 DESCRIPTION="update release changes"
23 VERSION="1.0.0"
24 ISSUE_URL= "https://dev.icinga.org/issues/"
25 ISSUE_PROJECT="i2"
26
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)")
32
33 args = arg_parser.parse_args(sys.argv[1:])
34
35 ftype = "md" if not args.html else "html"
36
37 def format_header(text, lvl, ftype = ftype):
38    if ftype == "html":
39        return "<h%s>%s</h%s>" % (lvl, text, lvl)
40    if ftype == "md":
41        return "#" * lvl + " " + text
42
43 def format_logentry(log_entry, args = args, issue_url = ISSUE_URL):
44    if args.links:
45        if args.html:
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)
47        else:
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)
49    else:
50        if args.html:
51            return "<li>%s %d (%s): %s</li>" % log_entry
52        else:
53            return "* %s %d (%s): %s" % log_entry
54
55 def print_category(category, entries):
56     if len(entries) > 0:
57         print ""
58         print format_header(category, 4)
59         print ""
60         if args.html:
61             print "<ul>"
62
63         for entry in sorted(entries):
64             print format_logentry(entry)
65
66         if args.html:
67             print "</ul>"
68             print ""
69
70
71 version_name = args.version
72
73 if args.project:
74     ISSUE_PROJECT=args.project
75
76 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
77 versions_data = json.loads(rsp.read())
78
79 version_id = None
80
81 for version in versions_data["versions"]:
82     if version["name"] == version_name:
83         version_id = version["id"]
84         break
85
86 if version_id == None:
87     print "Version '%s' not found." % (version_name)
88     sys.exit(1)
89
90 changes = ""
91
92 if "custom_fields" in version:
93     for field in version["custom_fields"]:
94         if field["id"] == 14:
95             changes = field["value"]
96             break
97
98     changes = string.join(string.split(changes, "\r\n"), "\n")
99
100 print format_header("What's New in Version %s" % (version_name), 3)
101 print ""
102
103 if changes:
104     print format_header("Changes", 4)
105     print ""
106     print changes
107     print ""
108
109 offset = 0
110
111 features = []
112 bugfixes = []
113 support = []
114
115 while True:
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
122
123     if issues_count == 0:
124         break
125
126     for issue in issues_data["issues"]:
127         ignore_issue = False
128
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":
132                     ignore_issue = True
133                     break
134
135             if ignore_issue:
136                 continue
137
138         if "category" in issue:
139             category = issue["category"]["name"]
140         else:
141             category = "no category"
142
143         # the order is important for print_category()
144         entry = (issue["tracker"]["name"], issue["id"], category, issue["subject"].strip())
145
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)
152
153 print_category("Feature", features)
154 print_category("Bugfixes", bugfixes)
155 print_category("Support", support)
156
157
158 sys.exit(0)