3
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (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
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
# This software may be used and distributed according to the terms
19
# of the GNU General Public License, incorporated herein by reference.
21
from bzrlib.commands import Command
24
class cmd_close_trac_bugs(Command):
25
"""Close trac bugs marked as closed in this branch.
27
bugtracker should be the name of a bugtracker configured in your
28
Bazaar configuration, e.g. 'bitlbee' in the case you have:
30
trac_bitlbee_url = http://bugs.bitlbee.org/bitlbee/
32
trac_project should be the path to your local trac environment.
34
location should refer to a Bazaar branch but defaults to the current
38
takes_args = ["bugtracker?", "trac_project?", "location?"]
40
def run(self, bugtracker, trac_project=None, location=None):
41
from bzrlib.branch import Branch
42
from bzrlib.errors import BzrCommandError
43
from trac.env import Environment
44
from trac.ticket import Ticket
48
b = Branch.open(location)
49
from bzrlib.bugtracker import tracker_registry
50
trac_bt = tracker_registry.get("trac")
52
config = b.get_config()
54
if bugtracker is None:
55
bugtracker = config.get_user_option("bugtracker")
56
if bugtracker is None:
57
raise BzrCommandError("No bug tracker specified and none in "
60
bt = trac_bt.get(bugtracker, b)
62
raise BzrCommandError("No such trac bugtracker '%s' in configuration." %
64
if trac_project is None:
65
trac_project = config.get_user_option("trac_project")
66
if trac_project is None:
67
raise BzrCommandError("No trac project specified and none in"
69
env = Environment(trac_project)
70
db_cnx = env.get_db_cnx()
72
revids = [r for r in b.repository.get_ancestry(b.last_revision()) if r]
73
for i, rev in enumerate(b.repository.get_revisions(revids)):
74
if not 'bugs' in rev.properties:
76
for line in rev.properties['bugs'].splitlines():
77
(url, resolution) = line.rsplit(" ", 1)
78
if resolution != "fixed":
80
if not url.startswith(bt._base_url):
82
# FIXME: Use bzrlib.bugtracker to extract the id
83
bugid = int(url.rsplit("/")[-1])
84
ticket = Ticket(env, bugid)
85
if ticket['resolution'] == 'fixed':
86
# Don't attempt to close again
88
ticket['resolution'] = 'fixed'
89
ticket['status'] = 'close'
90
revno = b.revision_id_to_dotted_revno(rev.revision_id)
91
ticket.save_changes(author=rev.committer,
92
comment="Closed in revision %s." % revno)