From cb83e0c1b48de2d1add47c08f952ea4223442f0c Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Sat, 12 Jun 2021 21:29:11 +1000 Subject: [PATCH] Tracker command argument to Jira ticket in default browser --- mdk/commands/tracker.py | 14 +++++++++++++- mdk/jira.py | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mdk/commands/tracker.py b/mdk/commands/tracker.py index fc743f70..a2996ba9 100644 --- a/mdk/commands/tracker.py +++ b/mdk/commands/tracker.py @@ -33,6 +33,13 @@ class TrackerCommand(Command): _arguments = [ + ( + ['--open'], + { + 'action': 'store_true', + 'help': 'Open issue in browser' + } + ), ( ['-t', '--testing'], { @@ -95,9 +102,14 @@ def run(self, args): if not issue or not re.match('(MDL|mdl)?(-|_)?[1-9]+', issue): raise Exception('Invalid or unknown issue number') - self.Jira = Jira() self.mdl = 'MDL-' + re.sub(r'(MDL|mdl)(-|_)?', '', issue) + if args.open: + Jira.openInBrowser(self.mdl) + return + + self.Jira = Jira() + if args.addlabels: if 'triaged' in args.addlabels: self.argumentError('The label \'triaged\' cannot be added using MDK') diff --git a/mdk/jira.py b/mdk/jira.py index a7bad549..2c056be7 100644 --- a/mdk/jira.py +++ b/mdk/jira.py @@ -31,6 +31,7 @@ import logging import os import requests +import webbrowser import mimetypes try: import keyring @@ -398,6 +399,11 @@ def upload(self, key, filepath): return True + @staticmethod + def openInBrowser(key): + jiraurl = C.get('tracker.url').rstrip('/') + url = "{0}/browse/{1}".format(jiraurl, key) + webbrowser.open_new_tab(url) class JiraException(Exception): pass