/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 breezy/bugtracker.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
"""
43
43
 
44
44
 
45
 
_bugs_help = \
46
 
"""When making a commit, metadata about bugs fixed by that change can be
 
45
_bugs_help = """\
 
46
When making a commit, metadata about bugs fixed by that change can be
47
47
recorded by using the ``--fixes`` option. For each bug marked as fixed, an
48
48
entry is included in the 'bugs' revision property stating '<url> <status>'.
49
49
(The only ``status`` value currently supported is ``fixed.``)
186
186
        self.line = line
187
187
 
188
188
 
 
189
class InvalidBugUrl(errors.BzrError):
 
190
 
 
191
    _fmt = "Invalid bug URL: %(url)s"
 
192
 
 
193
    def __init__(self, url):
 
194
        self.url = url
 
195
 
 
196
 
189
197
class InvalidBugStatus(errors.BzrError):
190
198
 
191
199
    _fmt = ("Invalid bug status: '%(status)s'")
216
224
            tracker = tracker_type.get(abbreviated_bugtracker_name, branch)
217
225
            if tracker is not None:
218
226
                return tracker
219
 
        raise UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
220
 
                branch)
 
227
        raise UnknownBugTrackerAbbreviation(
 
228
            abbreviated_bugtracker_name, branch)
221
229
 
222
230
    def help_topic(self, topic):
223
231
        return _bugs_help
316
324
        if '{project}' not in self._base_url:
317
325
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
318
326
        return self._base_url.replace(
319
 
                '{project}', project).replace('{id}', str(bug_id))
 
327
            '{project}', project).replace('{id}', str(bug_id))
320
328
 
321
329
 
322
330
tracker_registry.register(
327
335
    'debian', UniqueIntegerBugTracker('deb', 'http://bugs.debian.org/'))
328
336
 
329
337
 
330
 
tracker_registry.register('gnome',
331
 
    UniqueIntegerBugTracker('gnome',
332
 
                            'http://bugzilla.gnome.org/show_bug.cgi?id='))
 
338
tracker_registry.register(
 
339
    'gnome', UniqueIntegerBugTracker(
 
340
        'gnome', 'http://bugzilla.gnome.org/show_bug.cgi?id='))
333
341
 
334
342
 
335
343
tracker_registry.register(
377
385
    'squid' or 'apache').
378
386
    """
379
387
 
 
388
 
380
389
tracker_registry.register(
381
390
    'trac', URLParametrizedIntegerBugTracker('trac', 'ticket/'))
382
391
 
406
415
 
407
416
 
408
417
FIXED = 'fixed'
 
418
RELATED = 'related'
409
419
 
410
 
ALLOWED_BUG_STATUSES = {FIXED}
 
420
ALLOWED_BUG_STATUSES = {FIXED, RELATED}
411
421
 
412
422
 
413
423
def encode_fixes_bug_urls(bug_urls):
414
424
    """Get the revision property value for a commit that fixes bugs.
415
425
 
416
 
    :param bug_urls: An iterable of escaped URLs to bugs. These normally
 
426
    :param bug_urls: An iterable of (escaped URL, tag) tuples. These normally
417
427
        come from `get_bug_url`.
418
428
    :return: A string that will be set as the 'bugs' property of a revision
419
429
        as part of a commit.
420
430
    """
421
 
    return '\n'.join(('%s %s' % (url, FIXED)) for url in bug_urls)
 
431
    lines = []
 
432
    for (url, tag) in bug_urls:
 
433
        if ' ' in url:
 
434
            raise InvalidBugUrl(url)
 
435
        lines.append('%s %s' % (url, tag))
 
436
    return '\n'.join(lines)
 
437
 
 
438
 
 
439
def decode_bug_urls(bug_text):
 
440
    """Decode a bug property text.
 
441
 
 
442
    :param bug_text: Contents of a bugs property
 
443
    :return: iterator over (url, status) tuples
 
444
    """
 
445
    for line in bug_text.splitlines():
 
446
        try:
 
447
            url, status = line.split(None, 2)
 
448
        except ValueError:
 
449
            raise InvalidLineInBugsProperty(line)
 
450
        if status not in ALLOWED_BUG_STATUSES:
 
451
            raise InvalidBugStatus(status)
 
452
        yield url, status