]> granicus.if.org Git - icinga2/blob - changelog.py
Update AUTHORS
[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 def print_category(category, entries):
58     if len(entries) > 0:
59         print ""
60         print format_header(category, 4)
61         print ""
62         if args.html:
63             print "<ul>"
64
65         for entry in sorted(entries):
66             print format_logentry(entry)
67
68         if args.html:
69             print "</ul>"
70             print ""
71
72
73 version_name = args.version
74
75 if args.project:
76     ISSUE_PROJECT=args.project
77
78 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
79 versions_data = json.loads(rsp.read())
80
81 version_id = None
82
83 for version in versions_data["versions"]:
84     if version["name"] == version_name:
85         version_id = version["id"]
86         break
87
88 if version_id == None:
89     print "Version '%s' not found." % (version_name)
90     sys.exit(1)
91
92 changes = ""
93
94 if "custom_fields" in version:
95     for field in version["custom_fields"]:
96         if field["id"] == 14:
97             changes = field["value"]
98             break
99
100     changes = string.join(string.split(changes, "\r\n"), "\n")
101
102 print format_header("What's New in Version %s" % (version_name), 3)
103 print ""
104
105 if changes:
106     print format_header("Changes", 4)
107     print ""
108     print changes
109     print ""
110
111 offset = 0
112
113 features = []
114 bugfixes = []
115 support = []
116
117 while True:
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
124
125     if issues_count == 0:
126         break
127
128     for issue in issues_data["issues"]:
129         ignore_issue = False
130
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":
134                     ignore_issue = True
135                     break
136
137             if ignore_issue:
138                 continue
139
140         entry = (issue["tracker"]["name"], issue["id"], issue["subject"].strip())
141
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)
148
149 print_category("Feature", features)
150 print_category("Bugfixes", bugfixes)
151 print_category("Support", support)
152
153
154 sys.exit(0)