/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-17 17:43:14 UTC
  • mfrom: (7182.1.6 bad-bug-url)
  • Revision ID: breezy.the.bot@gmail.com-20181117174314-l591ms2d6aelafv6
Improve handling of bad bug urls:

* Raise an exception when invalid bug URLs are specified to 'brz commit'
* Print exceptions when customer log handlers raise an exception
  rather than aborting altogether.

Merged from https://code.launchpad.net/~jelmer/brz/bad-bug-url/+merge/358942

Show diffs side-by-side

added added

removed removed

Lines of Context:
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'")
420
428
    :return: A string that will be set as the 'bugs' property of a revision
421
429
        as part of a commit.
422
430
    """
423
 
    return '\n'.join(('%s %s' % (url, tag)) for (url, tag) 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