summaryrefslogtreecommitdiff
blob: 76c7e594c4cc439d6402f4772bdfe444a32aa586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python2
# Copyright 2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import datetime
import optparse
import os.path
import sys

from bugz.bugzilla import BugzillaProxy
import portage.versions

from common import Bug, chunks, login, detect_cpvs


def keyword_to_email(keyword):
	if keyword == 'arm64':
		keyword = 'arm'
	return '%s@gentoo.org' % keyword


if __name__ == "__main__":
	parser = optparse.OptionParser()
	parser.add_option("--days", dest="days", type=int, default=30, help="Number of days after maintainer timeout occurs.")
	(options, args) = parser.parse_args()
	if args:
		parser.error("unrecognized command-line args")

	url = 'https://bugs.gentoo.org/xmlrpc.cgi'
	print 'You will be prompted for your Gentoo Bugzilla username and password (%s).' % url
	bugzilla = BugzillaProxy(url)
	user, login_data = login(bugzilla)
	
	bugs = bugzilla.Bug.search({'reporter': user, 'summary': ['stabilize', 'stabilization', 'stable'], 'resolution': ''})['bugs']
	comments = bugzilla.Bug.comments({'ids': [bug['id'] for bug in bugs]})
	for bug in bugs:
		# Skip bugs where stabilization seems to be already in progress.
		arch_found = False
		for arch in portage.archlist:
			if '%s@gentoo.org' % arch in bug['cc']:
				arch_found = True
				break
		if arch_found:
			continue

		# Skip bugs without STABLEREQ keyword.
		if 'STABLEREQ' not in bug['keywords']:
			continue

		# Skip bugs with comments, they may indicate objections or problem reports.
		if len(comments['bugs'][str(bug['id'])]['comments']) > 1:
			continue

		# Skip too recent bugs.
		creation_time = datetime.datetime.strptime(str(bug['creation_time']), '%Y%m%dT%H:%M:%S')
		if datetime.datetime.now() - creation_time < datetime.timedelta(days=options.days):
			continue

		cpvs = detect_cpvs(bug['summary'])
		if len(cpvs) != 1:
			continue

		target_keywords = set()
		cp = portage.versions.cpv_getkey(cpvs[0])
		for cpv in portage.portdb.cp_list(cp):
			for keyword in portage.portdb.aux_get(cpv, ['KEYWORDS'])[0].split():
				if '~' not in keyword and '-' not in keyword:
					target_keywords.add(keyword)

		params = {}
		params['ids'] = [bug['id']]
		params['cc'] = {}
		params['cc']['add'] = list(set(keyword_to_email(k) for k in target_keywords))
		params['comment'] = {}
		params['comment']['body'] = 'Maintainer timeout (%d days). Arches please go ahead.' % options.days

		bugzilla.Bug.update(params)
		print 'Updated bug #%s (%s). Target KEYWORDS: %s ;-)' % (
			bug['id'],
			bug['summary'],
			', '.join(list(target_keywords)))