Skip to content

Commit

Permalink
Tracker command argument to open Jira ticket in default browser
Browse files Browse the repository at this point in the history
  • Loading branch information
dcai authored and FMCorz committed Oct 14, 2022
1 parent 7ff5ba9 commit a8ed3ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mdk/commands/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
class TrackerCommand(Command):

_arguments = [
(
['--open'],
{
'action': 'store_true',
'help': 'Open issue in browser'
}
),
(
['-t', '--testing'],
{
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions mdk/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import logging
import os
import requests
import webbrowser
import mimetypes
try:
import keyring
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a8ed3ee

Please sign in to comment.