3 # Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)
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.
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.
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.
19 import urllib2, json, sys, string, subprocess, re, os
20 from argparse import ArgumentParser
22 from tempfile import NamedTemporaryFile
24 DESCRIPTION="cherry-pick commits for releases"
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="project")
33 args = arg_parser.parse_args(sys.argv[1:])
35 version_name = args.version
38 ISSUE_PROJECT=args.project
40 rsp = urllib2.urlopen("https://dev.icinga.org/projects/%s/versions.json" % (ISSUE_PROJECT))
41 versions_data = json.loads(rsp.read())
45 for version in versions_data["versions"]:
46 if version["name"] == version_name:
47 version_id = version["id"]
50 if version_id == None:
51 print "Version '%s' not found." % (version_name)
59 # We could filter using &cf_13=1, however this doesn't currently work because the custom field isn't set
60 # for some of the older tickets:
61 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))
62 issues_data = json.loads(rsp.read())
63 issues_count = len(issues_data["issues"])
64 offset = offset + issues_count
69 for issue in issues_data["issues"]:
72 if "custom_fields" in issue:
73 for field in issue["custom_fields"]:
74 if field["id"] == 12 and "value" in field and field["value"] != "0":
81 issues.add(issue["id"])
85 new_branch = repo.create_head("auto-merged-" + version_name, "support/" + ".".join(version_name.split(".")[:-1]))
88 commits = reversed(list(repo.iter_commits(rev="master")))
90 tmpEditor = NamedTemporaryFile()
92 tmpEditor.write("#!/bin/sh\ncat > $1 <<COMMITS\n")
94 for commit in commits:
95 ids = set([int(id) for id in re.findall('#(?P<id>\d+)', commit.message)])
97 if not ids.intersection(issues):
100 tmpEditor.write("pick %s\n" % commit.hexsha)
102 tmpEditor.write("COMMITS")
105 os.chmod(tmpEditor.name, 0700)
107 env = os.environ.copy()
108 env["EDITOR"] = tmpEditor.name
110 subprocess.call(["git", "rebase", "-i", "HEAD"], env=env)