/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-05-15 10:20:16 UTC
  • mfrom: (6967 work)
  • mto: (6973.5.1 python3-c)
  • mto: This revision was merged to the branch mainline in revision 6984.
  • Revision ID: jelmer@jelmer.uk-20180515102016-tnlhsl574pfpplin
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
        self.base_url = base_url
269
269
 
270
270
    def get(self, abbreviated_bugtracker_name, branch):
271
 
        """Returns the tracker if the abbreviation matches. Returns None
272
 
        otherwise."""
 
271
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
 
272
        """
273
273
        if abbreviated_bugtracker_name != self.abbreviation:
274
274
            return None
275
275
        return self
279
279
        return self.base_url + str(bug_id)
280
280
 
281
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))
 
320
 
 
321
 
282
322
tracker_registry.register(
283
323
    'launchpad', UniqueIntegerBugTracker('lp', 'https://launchpad.net/bugs/'))
284
324
 
292
332
                            'http://bugzilla.gnome.org/show_bug.cgi?id='))
293
333
 
294
334
 
 
335
tracker_registry.register(
 
336
    'github', ProjectIntegerBugTracker(
 
337
        'github', 'https://github.com/{project}/issues/{id}'))
 
338
 
 
339
 
295
340
class URLParametrizedBugTracker(BugTracker):
296
341
    """A type of bug tracker that can be found on a variety of different sites,
297
342
    and thus needs to have the base URL configured.