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_env 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_env", "location?"]
40
def run(self, bugtracker, trac_env, 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
bt = trac_bt.get(bugtracker, b)
54
raise BzrCommandError("No such trac bugtracker '%s' in configuration." %
56
env = Environment(trac_env)
57
db_cnx = env.get_db_cnx()
59
revids = [r for r in b.repository.get_ancestry(b.last_revision()) if r]
60
for i, rev in enumerate(b.repository.get_revisions(revids)):
61
if not 'bugs' in rev.properties:
63
for line in rev.properties['bugs'].splitlines():
64
(url, resolution) = line.rsplit(" ", 1)
65
if resolution != "fixed":
67
if not url.startswith(bt._base_url):
69
# FIXME: Use bzrlib.bugtracker to extract the id
70
bugid = int(url.rsplit("/")[-1])
71
ticket = Ticket(env, bugid)
72
if ticket['resolution'] == 'fixed':
73
# Don't attempt to close again
75
ticket['resolution'] = 'fixed'
76
ticket['status'] = 'close'
77
revno = b.revision_id_to_dotted_revno(rev.revision_id)
78
ticket.save_changes(author=rev.committer,
79
comment="Closed in revision %s." % revno)