]> granicus.if.org Git - icinga2/blob - changelog.py
Ignore -W and -K arguments for check_disk on Windows
[icinga2] / changelog.py
1 #!/usr/bin/env python
2 #/******************************************************************************
3 # * Icinga 2                                                                   *
4 # * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)    *
5 # *                                                                            *
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.                     *
10 # *                                                                            *
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.                               *
15 # *                                                                            *
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 # ******************************************************************************/
20
21 import urllib2, json, sys, string
22 from argparse import ArgumentParser
23
24 DESCRIPTION="update release changes"
25 VERSION="1.0.0"
26 ISSUE_URL= "https://dev.icinga.org/issues/"
27 ISSUE_PROJECT="i2"
28
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)")
34
35 args = arg_parser.parse_args(sys.argv[1:])
36
37 ftype = "md" if not args.html else "html"
38
39 def format_header(text, lvl, ftype = ftype):
40    if ftype == "html":
41        return "<h%s>%s</h%s>" % (lvl, text, lvl)
42    if ftype == "md":
43        return "#" * lvl + " " + text
44
45 def format_logentry(log_entry, args = args, issue_url = ISSUE_URL):
46    if args.links:
47        if args.html:
48            return "<li> {0} <a href=\"{3}{1}\">{1}</a>: {2}</li>".format(log_entry[0], log_entry[1], log_entry[2], issue_url)
49        else:
50            return "* {0} [{1}]({3}{1} \"{0} {1}\"): {2}".format(log_entry[0], log_entry[1], log_entry[2], issue_url)
51    else:
52        if args.html:
53            return "<li>%s %d: %s</li>" % log_entry
54        else:
55            return "* %s %d: %s" % log_entry
56
57
58 version_name = args.version
59
60 if args.project:
61     ISSUE_PROJECT=args.project
62
63 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
64 versions_data = json.loads(rsp.read())
65
66 version_id = None
67
68 for version in versions_data["versions"]:
69     if version["name"] == version_name:
70         version_id = version["id"]
71         break
72
73 if version_id == None:
74     print "Version '%s' not found." % (version_name)
75     sys.exit(1)
76
77 changes = ""
78
79 if "custom_fields" in version:
80     for field in version["custom_fields"]:
81         if field["id"] == 14:
82             changes = field["value"]
83             break
84
85     changes = string.join(string.split(changes, "\r\n"), "\n")
86
87 print format_header("What's New in Version %s" % (version_name), 3)
88 print ""
89
90 if changes:
91     print format_header("Changes", 4)
92     print ""
93     print changes
94     print ""
95
96 offset = 0
97
98 log_entries = []
99
100 while True:
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
107
108     if issues_count == 0:
109         break
110
111     for issue in issues_data["issues"]:
112         ignore_issue = False
113
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":
117                     ignore_issue = True
118                     break
119
120             if ignore_issue:
121                 continue
122
123         log_entries.append((issue["tracker"]["name"], issue["id"], issue["subject"].strip()))
124
125 for p in range(2):
126     not_empty = False
127
128     for log_entry in log_entries:
129         if (p == 0 and log_entry[0] == "Feature") or (p == 1 and log_entry[0] != "Feature"):
130             not_empty = True
131
132     if not_empty:
133         print format_header("Features", 4) if p == 0 else format_header("Bugfixes", 4)
134         print ""
135         if args.html:
136             print "<ul>"
137
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)
141
142     if not_empty:
143         if args.html:
144             print "</ul>"
145
146         print ""
147
148 sys.exit(0)