-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira-query.py
executable file
·67 lines (58 loc) · 1.71 KB
/
jira-query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# coding: utf-8
"""
Description:
Launch a browser with the URL to Jira with a JQL query. On iOS Pythonista supports App Share and clipboard, on linux/Mac OS supports command line arguments.
License:
The MIT License (MIT)
Copyright (c) 2016 Nik Khilnani
Github:
https://github.com/khilnani/jira.py
Configuration:
Rename 'jira.sample.conf' to 'jira.conf' and update values
To use:
1 - In any app, use App Share, Run in Pythonista and then select this script
2 - Copy text and run this script within Pythonista.
"""
import appex
import clipboard
import console
import webbrowser
import json
import os
import urllib
from objc_util import *
CONF_NAME = 'jira.conf'
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
CONF_FILE = os.path.join(SCRIPT_DIR, CONF_NAME)
def get_conf_info():
try:
with open(CONF_FILE, 'r') as conf_file:
conf = json.load(conf_file)
url = conf['BASE_URL']
try:
user = conf['USER']
except KeyError:
user = None
return (url, user)
except IOError:
logging.error('Could not find %s' % CONF_FILE)
sys.exit()
def main():
text = None
if appex.is_running_extension():
text = appex.get_text()
if not text:
text = console.input_alert('Jira Query')
if text:
base_url, username = get_conf_info()
url = '%s/issues/?jql=%s' % (base_url, urllib.quote_plus(text))
console.hud_alert('Launching Jira')
app=UIApplication.sharedApplication()
url=nsurl(url)
app.openURL_(url)
else:
console.hud_alert('No input text found.')
if appex.is_running_extension():
appex.finish()
if __name__ == '__main__':
main()