/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: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

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
 
17
19
from . import (
18
20
    errors,
19
21
    registry,
40
42
"""
41
43
 
42
44
 
43
 
_bugs_help = """\
44
 
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
45
47
recorded by using the ``--fixes`` option. For each bug marked as fixed, an
46
48
entry is included in the 'bugs' revision property stating '<url> <status>'.
47
49
(The only ``status`` value currently supported is ``fixed.``)
184
186
        self.line = line
185
187
 
186
188
 
187
 
class InvalidBugUrl(errors.BzrError):
188
 
 
189
 
    _fmt = "Invalid bug URL: %(url)s"
190
 
 
191
 
    def __init__(self, url):
192
 
        self.url = url
193
 
 
194
 
 
195
189
class InvalidBugStatus(errors.BzrError):
196
190
 
197
191
    _fmt = ("Invalid bug status: '%(status)s'")
222
216
            tracker = tracker_type.get(abbreviated_bugtracker_name, branch)
223
217
            if tracker is not None:
224
218
                return tracker
225
 
        raise UnknownBugTrackerAbbreviation(
226
 
            abbreviated_bugtracker_name, branch)
 
219
        raise UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
 
220
                branch)
227
221
 
228
222
    def help_topic(self, topic):
229
223
        return _bugs_help
274
268
        self.base_url = base_url
275
269
 
276
270
    def get(self, abbreviated_bugtracker_name, branch):
277
 
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
278
 
        """
 
271
        """Returns the tracker if the abbreviation matches. Returns None
 
272
        otherwise."""
279
273
        if abbreviated_bugtracker_name != self.abbreviation:
280
274
            return None
281
275
        return self
285
279
        return self.base_url + str(bug_id)
286
280
 
287
281
 
288
 
class ProjectIntegerBugTracker(IntegerBugTracker):
289
 
    """A bug tracker that exists in one place only with per-project ids.
290
 
 
291
 
    If you have one of these trackers then register an instance passing in an
292
 
    abbreviated name for the bug tracker and a base URL. The bug ids are
293
 
    appended directly to the URL.
294
 
    """
295
 
 
296
 
    def __init__(self, abbreviated_bugtracker_name, base_url):
297
 
        self.abbreviation = abbreviated_bugtracker_name
298
 
        self._base_url = base_url
299
 
 
300
 
    def get(self, abbreviated_bugtracker_name, branch):
301
 
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
302
 
        """
303
 
        if abbreviated_bugtracker_name != self.abbreviation:
304
 
            return None
305
 
        return self
306
 
 
307
 
    def check_bug_id(self, bug_id):
308
 
        try:
309
 
            (project, bug_id) = bug_id.rsplit('/', 1)
310
 
        except ValueError:
311
 
            raise MalformedBugIdentifier(bug_id, "Expected format: project/id")
312
 
        try:
313
 
            int(bug_id)
314
 
        except ValueError:
315
 
            raise MalformedBugIdentifier(bug_id, "Bug id must be an integer")
316
 
 
317
 
    def _get_bug_url(self, bug_id):
318
 
        (project, bug_id) = bug_id.rsplit('/', 1)
319
 
        """Return the URL for bug_id."""
320
 
        if '{id}' not in self._base_url:
321
 
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
322
 
        if '{project}' not in self._base_url:
323
 
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
324
 
        return self._base_url.replace(
325
 
            '{project}', project).replace('{id}', str(bug_id))
326
 
 
327
 
 
328
282
tracker_registry.register(
329
283
    'launchpad', UniqueIntegerBugTracker('lp', 'https://launchpad.net/bugs/'))
330
284
 
333
287
    'debian', UniqueIntegerBugTracker('deb', 'http://bugs.debian.org/'))
334
288
 
335
289
 
336
 
tracker_registry.register(
337
 
    'gnome', UniqueIntegerBugTracker(
338
 
        'gnome', 'http://bugzilla.gnome.org/show_bug.cgi?id='))
339
 
 
340
 
 
341
 
tracker_registry.register(
342
 
    'github', ProjectIntegerBugTracker(
343
 
        'github', 'https://github.com/{project}/issues/{id}'))
 
290
tracker_registry.register('gnome',
 
291
    UniqueIntegerBugTracker('gnome',
 
292
                            'http://bugzilla.gnome.org/show_bug.cgi?id='))
344
293
 
345
294
 
346
295
class URLParametrizedBugTracker(BugTracker):
383
332
    'squid' or 'apache').
384
333
    """
385
334
 
386
 
 
387
335
tracker_registry.register(
388
336
    'trac', URLParametrizedIntegerBugTracker('trac', 'ticket/'))
389
337
 
413
361
 
414
362
 
415
363
FIXED = 'fixed'
416
 
RELATED = 'related'
417
364
 
418
 
ALLOWED_BUG_STATUSES = {FIXED, RELATED}
 
365
ALLOWED_BUG_STATUSES = {FIXED}
419
366
 
420
367
 
421
368
def encode_fixes_bug_urls(bug_urls):
422
369
    """Get the revision property value for a commit that fixes bugs.
423
370
 
424
 
    :param bug_urls: An iterable of (escaped URL, tag) tuples. These normally
 
371
    :param bug_urls: An iterable of escaped URLs to bugs. These normally
425
372
        come from `get_bug_url`.
426
373
    :return: A string that will be set as the 'bugs' property of a revision
427
374
        as part of a commit.
428
375
    """
429
 
    lines = []
430
 
    for (url, tag) in bug_urls:
431
 
        if ' ' in url:
432
 
            raise InvalidBugUrl(url)
433
 
        lines.append('%s %s' % (url, tag))
434
 
    return '\n'.join(lines)
435
 
 
436
 
 
437
 
def decode_bug_urls(bug_text):
438
 
    """Decode a bug property text.
439
 
 
440
 
    :param bug_text: Contents of a bugs property
441
 
    :return: iterator over (url, status) tuples
442
 
    """
443
 
    for line in bug_text.splitlines():
444
 
        try:
445
 
            url, status = line.split(None, 2)
446
 
        except ValueError:
447
 
            raise InvalidLineInBugsProperty(line)
448
 
        if status not in ALLOWED_BUG_STATUSES:
449
 
            raise InvalidBugStatus(status)
450
 
        yield url, status
 
376
    return '\n'.join(('%s %s' % (url, FIXED)) for url in bug_urls)