| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
from breezy import commands, errors, trace, bugtracker |
| 21 |
from breezy.config import GlobalConfig |
| 22 |
from breezy.branch import Branch |
| 23 |
from breezy.option import Option |
| 24 |
|
| 25 |
from breezy.plugins.qbrz.lib.bugs import FakeBranchForBugs |
| 26 |
|
| 27 |
|
| 28 |
class cmd_bug_url(commands.Command): |
| 29 |
"""Print full URL to a specific bug, or open it in your browser.""" |
| 30 |
|
| 31 |
takes_args = ['bug_id'] |
| 32 |
takes_options = [ |
| 33 |
Option('open', help='Open the URL in a web browser.'), |
| 34 |
] |
| 35 |
|
| 36 |
def run(self, bug_id, open=False): |
| 37 |
|
| 38 |
|
| 39 |
from breezy.plugins.qbrz.lib.util import open_browser, url_for_display |
| 40 |
try: |
| 41 |
branch = Branch.open_containing('.')[0] |
| 42 |
except errors.NotBranchError: |
| 43 |
branch = FakeBranchForBugs() |
| 44 |
tokens = bug_id.split(':') |
| 45 |
if len(tokens) != 2: |
| 46 |
raise errors.BzrCommandError("Invalid bug %s. Must be in the form of 'tag:id'." % bug_id) |
| 47 |
tag, tag_bug_id = tokens |
| 48 |
try: |
| 49 |
bug_url = bugtracker.get_bug_url(tag, branch, tag_bug_id) |
| 50 |
except errors.UnknownBugTrackerAbbreviation: |
| 51 |
raise errors.BzrCommandError('Unrecognized bug %s.' % bug_id) |
| 52 |
except errors.MalformedBugIdentifier: |
| 53 |
raise errors.BzrCommandError("Invalid bug identifier for %s." % bug_id) |
| 54 |
self.outf.write(url_for_display(bug_url) + "\n") |
| 55 |
if open: |
| 56 |
open_browser(bug_url) |