/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: 2017-07-20 00:00:04 UTC
  • mfrom: (6690.5.2 bundle-guess)
  • Revision ID: jelmer@jelmer.uk-20170720000004-wlknc5gthdk3tokn
Merge lp:~jelmer/brz/bundle-guess.

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 bzrlib import registry
18
 
from bzrlib.lazy_import import lazy_import
 
17
from __future__ import absolute_import
 
18
 
 
19
from . import (
 
20
    errors,
 
21
    registry,
 
22
    )
 
23
from .lazy_import import lazy_import
19
24
lazy_import(globals(), """
20
 
from bzrlib import errors, urlutils
 
25
from breezy import urlutils
21
26
""")
22
27
 
23
28
 
48
53
 
49
54
    bzr commit --fixes <tracker>:<id>
50
55
 
 
56
or::
 
57
 
 
58
    bzr commit --fixes <id>
 
59
 
51
60
where "<tracker>" is an identifier for the bug tracker, and "<id>" is the
52
61
identifier for that bug within the bugtracker, usually the bug number.
 
62
If "<tracker>" is not specified the ``bugtracker`` set in the branch
 
63
or global configuration is used.
53
64
 
54
65
Bazaar knows about a few bug trackers that have many users. If
55
66
you use one of these bug trackers then there is no setup required to
93
104
--fixes`` to mark bugs in that tracker as being fixed by that commit. For
94
105
example::
95
106
 
96
 
    bugzilla_squid_url = http://www.squid-cache.org/bugs
 
107
    bugzilla_squid_url = http://bugs.squid-cache.org
97
108
 
98
109
would allow ``bzr commit --fixes squid:1234`` to mark Squid's bug 1234 as
99
110
fixed.
127
138
 
128
139
    bugtracker_cpan_url = http://rt.cpan.org/Public/Bug/Display.html?id={id}
129
140
 
130
 
for CPAN's RT bug tracker.
 
141
would allow ``bzr commit --fixes cpan:1234`` to mark bug 1234 in CPAN's
 
142
RT bug tracker as fixed, or::
 
143
 
 
144
    bugtracker_hudson_url = http://issues.hudson-ci.org/browse/{id}
 
145
 
 
146
would allow ``bzr commit --fixes hudson:HUDSON-1234`` to mark bug HUDSON-1234
 
147
in Hudson's JIRA bug tracker as fixed.
131
148
"""
132
149
 
133
150
 
 
151
class MalformedBugIdentifier(errors.BzrError):
 
152
 
 
153
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
154
            'See "brz help bugs" for more information on this feature.')
 
155
 
 
156
    def __init__(self, bug_id, reason):
 
157
        self.bug_id = bug_id
 
158
        self.reason = reason
 
159
 
 
160
 
 
161
class InvalidBugTrackerURL(errors.BzrError):
 
162
 
 
163
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
164
            "contain {id}: %(url)s")
 
165
 
 
166
    def __init__(self, abbreviation, url):
 
167
        self.abbreviation = abbreviation
 
168
        self.url = url
 
169
 
 
170
 
 
171
class UnknownBugTrackerAbbreviation(errors.BzrError):
 
172
 
 
173
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
174
            "on %(branch)s")
 
175
 
 
176
    def __init__(self, abbreviation, branch):
 
177
        self.abbreviation = abbreviation
 
178
        self.branch = branch
 
179
 
 
180
 
 
181
class InvalidLineInBugsProperty(errors.BzrError):
 
182
 
 
183
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
184
 
 
185
    def __init__(self, line):
 
186
        self.line = line
 
187
 
 
188
 
 
189
class InvalidBugStatus(errors.BzrError):
 
190
 
 
191
    _fmt = ("Invalid bug status: '%(status)s'")
 
192
 
 
193
    def __init__(self, status):
 
194
        self.status = status
 
195
 
 
196
 
134
197
def get_bug_url(abbreviated_bugtracker_name, branch, bug_id):
135
198
    """Return a URL pointing to the canonical web page of the bug identified by
136
199
    'bug_id'.
153
216
            tracker = tracker_type.get(abbreviated_bugtracker_name, branch)
154
217
            if tracker is not None:
155
218
                return tracker
156
 
        raise errors.UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
157
 
                                                   branch)
 
219
        raise UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
 
220
                branch)
158
221
 
159
222
    def help_topic(self, topic):
160
223
        return _bugs_help
189
252
        try:
190
253
            int(bug_id)
191
254
        except ValueError:
192
 
            raise errors.MalformedBugIdentifier(bug_id, "Must be an integer")
 
255
            raise MalformedBugIdentifier(bug_id, "Must be an integer")
193
256
 
194
257
 
195
258
class UniqueIntegerBugTracker(IntegerBugTracker):
225
288
 
226
289
 
227
290
tracker_registry.register('gnome',
228
 
    UniqueIntegerBugTracker('gnome', 'http://bugzilla.gnome.org/show_bug.cgi?id='))
229
 
 
230
 
 
231
 
class URLParametrizedIntegerBugTracker(IntegerBugTracker):
 
291
    UniqueIntegerBugTracker('gnome',
 
292
                            'http://bugzilla.gnome.org/show_bug.cgi?id='))
 
293
 
 
294
 
 
295
class URLParametrizedBugTracker(BugTracker):
232
296
    """A type of bug tracker that can be found on a variety of different sites,
233
297
    and thus needs to have the base URL configured.
234
298
 
235
299
    Looks for a config setting in the form '<type_name>_<abbreviation>_url'.
236
 
    `type_name` is the name of the type of tracker (e.g. 'bugzilla' or 'trac')
237
 
    and `abbreviation` is a short name for the particular instance (e.g.
238
 
    'squid' or 'apache').
 
300
    `type_name` is the name of the type of tracker and `abbreviation`
 
301
    is a short name for the particular instance.
239
302
    """
240
303
 
241
304
    def get(self, abbreviation, branch):
242
305
        config = branch.get_config()
243
306
        url = config.get_user_option(
244
 
            "%s_%s_url" % (self.type_name, abbreviation))
 
307
            "%s_%s_url" % (self.type_name, abbreviation), expand=False)
245
308
        if url is None:
246
309
            return None
247
310
        self._base_url = url
256
319
        return urlutils.join(self._base_url, self._bug_area) + str(bug_id)
257
320
 
258
321
 
 
322
class URLParametrizedIntegerBugTracker(IntegerBugTracker,
 
323
                                       URLParametrizedBugTracker):
 
324
    """A type of bug tracker that  only allows integer bug IDs.
 
325
 
 
326
    This can be found on a variety of different sites, and thus needs to have
 
327
    the base URL configured.
 
328
 
 
329
    Looks for a config setting in the form '<type_name>_<abbreviation>_url'.
 
330
    `type_name` is the name of the type of tracker (e.g. 'bugzilla' or 'trac')
 
331
    and `abbreviation` is a short name for the particular instance (e.g.
 
332
    'squid' or 'apache').
 
333
    """
 
334
 
259
335
tracker_registry.register(
260
336
    'trac', URLParametrizedIntegerBugTracker('trac', 'ticket/'))
261
337
 
264
340
    URLParametrizedIntegerBugTracker('bugzilla', 'show_bug.cgi?id='))
265
341
 
266
342
 
267
 
class GenericBugTracker(URLParametrizedIntegerBugTracker):
 
343
class GenericBugTracker(URLParametrizedBugTracker):
268
344
    """Generic bug tracker specified by an URL template."""
269
345
 
270
346
    def __init__(self):
277
353
    def _get_bug_url(self, bug_id):
278
354
        """Given a validated bug_id, return the bug's web page's URL."""
279
355
        if '{id}' not in self._base_url:
280
 
            raise errors.InvalidBugTrackerURL(self._abbreviation,
281
 
                                              self._base_url)
 
356
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
282
357
        return self._base_url.replace('{id}', str(bug_id))
283
358
 
284
359
 
287
362
 
288
363
FIXED = 'fixed'
289
364
 
290
 
ALLOWED_BUG_STATUSES = set([FIXED])
 
365
ALLOWED_BUG_STATUSES = {FIXED}
291
366
 
292
367
 
293
368
def encode_fixes_bug_urls(bug_urls):