summaryrefslogtreecommitdiffstats
path: root/client/bug_show.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/bug_show.py')
-rwxr-xr-xclient/bug_show.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/client/bug_show.py b/client/bug_show.py
new file mode 100755
index 0000000..0c3c9b8
--- /dev/null
+++ b/client/bug_show.py
@@ -0,0 +1,55 @@
+#!../flask/bin/python
+"""
+usage: bug show [options] <ticket_id>
+
+ -h, --help Print this help text
+"""
+from docopt import docopt
+from textwrap import indent
+from datetime import datetime
+import json, requests
+
+if __name__ == '__main__':
+ print(docopt(__doc__))
+
+def call(args):
+ print(args)
+ api_endpoint = args['--uri'] + '/api/1.0/ticket/'
+
+ r = requests.get(api_endpoint + args['<ticket_id>'])
+
+ ticket = json.loads(r.text).get('ticket')
+ print(ticket)
+ print(show_ticket(ticket))
+
+def show_ticket(ticket):
+ output = '[TBT#{}] '.format(ticket['id'])
+
+ if 'deleted' in ticket and ticket['deleted'] == True:
+ output += '[DELETED] '
+
+ output += '[{}] '.format(ticket['status'])
+
+ output += '{}\n'.format(ticket['summary'])
+
+
+ if ticket['status'] != 'open':
+ output += 'Resolution: {}\n'.format(ticket['resolution'])
+
+ if ticket['reason']:
+ output += 'Reason: {}\n'.format(ticket['reason'])
+
+ output += 'Opened by: {} <{}>\n'.format(ticket['opened_by']['nickname'], ticket['opened_by']['email'])
+ output += 'Opened at: {} UTC\n'.format(datetime.strptime( ticket['opened_at'], "%Y-%m-%dT%H:%M:%S" ))
+
+ if ticket['assigned_to']:
+ output += 'Assigned to: {} <{}>\n'.format(ticket['assigned_to']['nickname'], ticket['assigned_to']['email'])
+ else:
+ output += 'Assigned to: Unassigned\n'
+
+ if ticket['updated_at']:
+ output += 'Updated at: {} UTC\n'.format(datetime.strptime(ticket['opened_at'], "%Y-%m-%dT%H:%M:%S" ))
+
+ output += '\n' + indent('{}'.format(ticket['body']), ' ') + '\n'
+
+ return output