/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bugtracker.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
 
from . import (
20
 
    errors,
21
 
    registry,
22
 
    )
23
 
from .lazy_import import lazy_import
 
17
from bzrlib import registry
 
18
from bzrlib.lazy_import import lazy_import
24
19
lazy_import(globals(), """
25
 
from breezy import urlutils
 
20
from bzrlib import errors, urlutils
26
21
""")
27
22
 
28
23
 
53
48
 
54
49
    bzr commit --fixes <tracker>:<id>
55
50
 
56
 
or::
57
 
 
58
 
    bzr commit --fixes <id>
59
 
 
60
51
where "<tracker>" is an identifier for the bug tracker, and "<id>" is the
61
52
identifier for that bug within the bugtracker, usually the bug number.
62
 
If "<tracker>" is not specified the ``bugtracker`` set in the branch
63
 
or global configuration is used.
64
53
 
65
54
Bazaar knows about a few bug trackers that have many users. If
66
55
you use one of these bug trackers then there is no setup required to
84
73
 
85
74
If you use Bugzilla or Trac, then you only need to set a configuration
86
75
variable which contains the base URL of the bug tracker. These options
87
 
can go into ``breezy.conf``, ``branch.conf`` or into a branch-specific
 
76
can go into ``bazaar.conf``, ``branch.conf`` or into a branch-specific
88
77
configuration section in ``locations.conf``.  You can set up these values
89
78
for each of the projects you work on.
90
79
 
104
93
--fixes`` to mark bugs in that tracker as being fixed by that commit. For
105
94
example::
106
95
 
107
 
    bugzilla_squid_url = http://bugs.squid-cache.org
 
96
    bugzilla_squid_url = http://www.squid-cache.org/bugs
108
97
 
109
98
would allow ``bzr commit --fixes squid:1234`` to mark Squid's bug 1234 as
110
99
fixed.
138
127
 
139
128
    bugtracker_cpan_url = http://rt.cpan.org/Public/Bug/Display.html?id={id}
140
129
 
141
 
would allow ``bzr commit --fixes cpan:1234`` to mark bug 1234 in CPAN's
142
 
RT bug tracker as fixed, or::
143
 
 
144
 
    bugtracker_hudson_url = http://issues.hudson-ci.org/browse/{id}
145
 
 
146
 
would allow ``bzr commit --fixes hudson:HUDSON-1234`` to mark bug HUDSON-1234
147
 
in Hudson's JIRA bug tracker as fixed.
 
130
for CPAN's RT bug tracker.
148
131
"""
149
132
 
150
133
 
151
 
class MalformedBugIdentifier(errors.BzrError):
152
 
 
153
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
154
 
            'See "brz help bugs" for more information on this feature.')
155
 
 
156
 
    def __init__(self, bug_id, reason):
157
 
        self.bug_id = bug_id
158
 
        self.reason = reason
159
 
 
160
 
 
161
 
class InvalidBugTrackerURL(errors.BzrError):
162
 
 
163
 
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
164
 
            "contain {id}: %(url)s")
165
 
 
166
 
    def __init__(self, abbreviation, url):
167
 
        self.abbreviation = abbreviation
168
 
        self.url = url
169
 
 
170
 
 
171
 
class UnknownBugTrackerAbbreviation(errors.BzrError):
172
 
 
173
 
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
174
 
            "on %(branch)s")
175
 
 
176
 
    def __init__(self, abbreviation, branch):
177
 
        self.abbreviation = abbreviation
178
 
        self.branch = branch
179
 
 
180
 
 
181
 
class InvalidLineInBugsProperty(errors.BzrError):
182
 
 
183
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
184
 
 
185
 
    def __init__(self, line):
186
 
        self.line = line
187
 
 
188
 
 
189
 
class InvalidBugStatus(errors.BzrError):
190
 
 
191
 
    _fmt = ("Invalid bug status: '%(status)s'")
192
 
 
193
 
    def __init__(self, status):
194
 
        self.status = status
195
 
 
196
 
 
197
134
def get_bug_url(abbreviated_bugtracker_name, branch, bug_id):
198
135
    """Return a URL pointing to the canonical web page of the bug identified by
199
136
    'bug_id'.
216
153
            tracker = tracker_type.get(abbreviated_bugtracker_name, branch)
217
154
            if tracker is not None:
218
155
                return tracker
219
 
        raise UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
220
 
                branch)
 
156
        raise errors.UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
 
157
                                                   branch)
221
158
 
222
159
    def help_topic(self, topic):
223
160
        return _bugs_help
252
189
        try:
253
190
            int(bug_id)
254
191
        except ValueError:
255
 
            raise MalformedBugIdentifier(bug_id, "Must be an integer")
 
192
            raise errors.MalformedBugIdentifier(bug_id, "Must be an integer")
256
193
 
257
194
 
258
195
class UniqueIntegerBugTracker(IntegerBugTracker):
268
205
        self.base_url = base_url
269
206
 
270
207
    def get(self, abbreviated_bugtracker_name, branch):
271
 
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
272
 
        """
273
 
        if abbreviated_bugtracker_name != self.abbreviation:
274
 
            return None
275
 
        return self
276
 
 
277
 
    def _get_bug_url(self, bug_id):
278
 
        """Return the URL for bug_id."""
279
 
        return self.base_url + str(bug_id)
280
 
 
281
 
 
282
 
class ProjectIntegerBugTracker(IntegerBugTracker):
283
 
    """A bug tracker that exists in one place only with per-project ids.
284
 
 
285
 
    If you have one of these trackers then register an instance passing in an
286
 
    abbreviated name for the bug tracker and a base URL. The bug ids are
287
 
    appended directly to the URL.
288
 
    """
289
 
 
290
 
    def __init__(self, abbreviated_bugtracker_name, base_url):
291
 
        self.abbreviation = abbreviated_bugtracker_name
292
 
        self._base_url = base_url
293
 
 
294
 
    def get(self, abbreviated_bugtracker_name, branch):
295
 
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
296
 
        """
297
 
        if abbreviated_bugtracker_name != self.abbreviation:
298
 
            return None
299
 
        return self
300
 
 
301
 
    def check_bug_id(self, bug_id):
302
 
        try:
303
 
            (project, bug_id) = bug_id.rsplit('/', 1)
304
 
        except ValueError:
305
 
            raise MalformedBugIdentifier(bug_id, "Expected format: project/id")
306
 
        try:
307
 
            int(bug_id)
308
 
        except ValueError:
309
 
            raise MalformedBugIdentifier(bug_id, "Bug id must be an integer")
310
 
 
311
 
    def _get_bug_url(self, bug_id):
312
 
        (project, bug_id) = bug_id.rsplit('/', 1)
313
 
        """Return the URL for bug_id."""
314
 
        if '{id}' not in self._base_url:
315
 
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
316
 
        if '{project}' not in self._base_url:
317
 
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
318
 
        return self._base_url.replace(
319
 
                '{project}', project).replace('{id}', str(bug_id))
 
208
        """Returns the tracker if the abbreviation matches. Returns None
 
209
        otherwise."""
 
210
        if abbreviated_bugtracker_name != self.abbreviation:
 
211
            return None
 
212
        return self
 
213
 
 
214
    def _get_bug_url(self, bug_id):
 
215
        """Return the URL for bug_id."""
 
216
        return self.base_url + bug_id
320
217
 
321
218
 
322
219
tracker_registry.register(
328
225
 
329
226
 
330
227
tracker_registry.register('gnome',
331
 
    UniqueIntegerBugTracker('gnome',
332
 
                            'http://bugzilla.gnome.org/show_bug.cgi?id='))
333
 
 
334
 
 
335
 
tracker_registry.register(
336
 
    'github', ProjectIntegerBugTracker(
337
 
        'github', 'https://github.com/{project}/issues/{id}'))
338
 
 
339
 
 
340
 
class URLParametrizedBugTracker(BugTracker):
 
228
    UniqueIntegerBugTracker('gnome', 'http://bugzilla.gnome.org/show_bug.cgi?id='))
 
229
 
 
230
 
 
231
class URLParametrizedIntegerBugTracker(IntegerBugTracker):
341
232
    """A type of bug tracker that can be found on a variety of different sites,
342
233
    and thus needs to have the base URL configured.
343
234
 
344
235
    Looks for a config setting in the form '<type_name>_<abbreviation>_url'.
345
 
    `type_name` is the name of the type of tracker and `abbreviation`
346
 
    is a short name for the particular instance.
 
236
    `type_name` is the name of the type of tracker (e.g. 'bugzilla' or 'trac')
 
237
    and `abbreviation` is a short name for the particular instance (e.g.
 
238
    'squid' or 'apache').
347
239
    """
348
240
 
349
241
    def get(self, abbreviation, branch):
350
242
        config = branch.get_config()
351
243
        url = config.get_user_option(
352
 
            "%s_%s_url" % (self.type_name, abbreviation), expand=False)
 
244
            "%s_%s_url" % (self.type_name, abbreviation))
353
245
        if url is None:
354
246
            return None
355
247
        self._base_url = url
364
256
        return urlutils.join(self._base_url, self._bug_area) + str(bug_id)
365
257
 
366
258
 
367
 
class URLParametrizedIntegerBugTracker(IntegerBugTracker,
368
 
                                       URLParametrizedBugTracker):
369
 
    """A type of bug tracker that  only allows integer bug IDs.
370
 
 
371
 
    This can be found on a variety of different sites, and thus needs to have
372
 
    the base URL configured.
373
 
 
374
 
    Looks for a config setting in the form '<type_name>_<abbreviation>_url'.
375
 
    `type_name` is the name of the type of tracker (e.g. 'bugzilla' or 'trac')
376
 
    and `abbreviation` is a short name for the particular instance (e.g.
377
 
    'squid' or 'apache').
378
 
    """
379
 
 
380
259
tracker_registry.register(
381
260
    'trac', URLParametrizedIntegerBugTracker('trac', 'ticket/'))
382
261
 
385
264
    URLParametrizedIntegerBugTracker('bugzilla', 'show_bug.cgi?id='))
386
265
 
387
266
 
388
 
class GenericBugTracker(URLParametrizedBugTracker):
 
267
class GenericBugTracker(URLParametrizedIntegerBugTracker):
389
268
    """Generic bug tracker specified by an URL template."""
390
269
 
391
270
    def __init__(self):
398
277
    def _get_bug_url(self, bug_id):
399
278
        """Given a validated bug_id, return the bug's web page's URL."""
400
279
        if '{id}' not in self._base_url:
401
 
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
 
280
            raise errors.InvalidBugTrackerURL(self._abbreviation,
 
281
                                              self._base_url)
402
282
        return self._base_url.replace('{id}', str(bug_id))
403
283
 
404
284
 
407
287
 
408
288
FIXED = 'fixed'
409
289
 
410
 
ALLOWED_BUG_STATUSES = {FIXED}
 
290
ALLOWED_BUG_STATUSES = set([FIXED])
411
291
 
412
292
 
413
293
def encode_fixes_bug_urls(bug_urls):