268
268
self.base_url = base_url
270
270
def get(self, abbreviated_bugtracker_name, branch):
271
"""Returns the tracker if the abbreviation matches. Returns None
271
"""Returns the tracker if the abbreviation matches, otherwise ``None``.
273
273
if abbreviated_bugtracker_name != self.abbreviation:
279
279
return self.base_url + str(bug_id)
282
class ProjectIntegerBugTracker(IntegerBugTracker):
283
"""A bug tracker that exists in one place only with per-project ids.
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.
290
def __init__(self, abbreviated_bugtracker_name, base_url):
291
self.abbreviation = abbreviated_bugtracker_name
292
self._base_url = base_url
294
def get(self, abbreviated_bugtracker_name, branch):
295
"""Returns the tracker if the abbreviation matches, otherwise ``None``.
297
if abbreviated_bugtracker_name != self.abbreviation:
301
def check_bug_id(self, bug_id):
303
(project, bug_id) = bug_id.rsplit('/', 1)
305
raise MalformedBugIdentifier(bug_id, "Expected format: project/id")
309
raise MalformedBugIdentifier(bug_id, "Bug id must be an integer")
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))
282
322
tracker_registry.register(
283
323
'launchpad', UniqueIntegerBugTracker('lp', 'https://launchpad.net/bugs/'))
292
332
'http://bugzilla.gnome.org/show_bug.cgi?id='))
335
tracker_registry.register(
336
'github', ProjectIntegerBugTracker(
337
'github', 'https://github.com/{project}/issues/{id}'))
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.